Commit feeb525b authored by François Michonneau's avatar François Michonneau
Browse files

use github metadata to identify branch to use when editing files

parent 71ace0f4
{% comment %}
identify the default branch of the GitHub repo for the lesson, to create the correct link for "Improve on GitHub"
{% endcomment %}
{% comment %}
First, get the name of the repository
{% endcomment %}
{% assign repo_name = site.github.repository_name %}
{% comment %}
`site.github.public_repositories` contains comprehensive information for all public repositories for the organization. We use `where` to extract the part
of the metadata that is relevant to the present repository.
{% endcomment %}
{% assign repo_info = site.github.public_repositories | where: "name", repo_name %}
{% comment %}
Now, we can extract the default branch for the repo
{% endcomment %}
{% assign default_branch = repo_info[0].default_branch %}
{% comment %}
Footer for lesson pages.
{% endcomment %}
{% include gh_default_branch.html %}
<footer>
<div class="row">
<div class="col-md-6 copyright" align="left">
......@@ -27,17 +30,17 @@
<div class="col-md-6 help-links" align="right">
{% if page.source %}
{% if page.source == "Rmd" %}
<a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Edit on GitHub</a>
<a href="{{site.github.repository_url}}/edit/{{ default_branch }}/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Edit on GitHub</a>
{% endif %}
{% else %}
<a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path}}">Edit on GitHub</a>
<a href="{{site.github.repository_url}}/edit/{{ default_branch }}/{{page.path}}">Edit on GitHub</a>
{% endif %}
/
<a href="{{ site.github.repository_url }}/blob/gh-pages/CONTRIBUTING.md">Contributing</a>
<a href="{{ site.github.repository_url }}/blob/{{ site.github.source.branch }}/CONTRIBUTING.md">Contributing</a>
/
<a href="{{ site.github.repository_url }}/">Source</a>
/
<a href="{{ site.github.repository_url }}/blob/gh-pages/CITATION">Cite</a>
<a href="{{ site.github.repository_url }}/blob/{{ site.github.source.branch }}/CITATION">Cite</a>
/
<a href="mailto:{{ site.email }}">Contact</a>
</div>
......
{% comment %}
Lesson navigation bar.
{% endcomment %}
{% include gh_default_branch.html %}
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
......@@ -74,10 +77,10 @@
<li><a href="{{ relative_root_path }}{% link LICENSE.md %}">License</a></li>
{% if page.source %}
{% if page.source == "Rmd" %}
<li><a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
<li><a href="{{site.github.repository_url}}/edit/{{ default_branch }}/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
{% endif %}
{% else %}
<li><a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path}}">Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
<li><a href="{{site.github.repository_url}}/edit/{{ default_branch}}/{{page.path}}">Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
{% endif %}
</ul>
<form class="navbar-form navbar-right" role="search" id="search" onsubmit="google_search(); return false;">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment