Skip to content

Commit feeb525

Browse files
committed
use github metadata to identify branch to use when editing files
1 parent 71ace0f commit feeb525

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

_includes/gh_default_branch.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% comment %}
2+
identify the default branch of the GitHub repo for the lesson, to create the correct link for "Improve on GitHub"
3+
{% endcomment %}
4+
5+
{% comment %}
6+
First, get the name of the repository
7+
{% endcomment %}
8+
{% assign repo_name = site.github.repository_name %}
9+
10+
{% comment %}
11+
`site.github.public_repositories` contains comprehensive information for all public repositories for the organization. We use `where` to extract the part
12+
of the metadata that is relevant to the present repository.
13+
{% endcomment %}
14+
{% assign repo_info = site.github.public_repositories | where: "name", repo_name %}
15+
16+
{% comment %}
17+
Now, we can extract the default branch for the repo
18+
{% endcomment %}
19+
{% assign default_branch = repo_info[0].default_branch %}

_includes/lesson_footer.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{% comment %}
22
Footer for lesson pages.
33
{% endcomment %}
4+
5+
{% include gh_default_branch.html %}
6+
47
<footer>
58
<div class="row">
69
<div class="col-md-6 copyright" align="left">
@@ -27,17 +30,17 @@
2730
<div class="col-md-6 help-links" align="right">
2831
{% if page.source %}
2932
{% if page.source == "Rmd" %}
30-
<a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Edit on GitHub</a>
33+
<a href="{{site.github.repository_url}}/edit/{{ default_branch }}/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Edit on GitHub</a>
3134
{% endif %}
3235
{% else %}
33-
<a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path}}">Edit on GitHub</a>
36+
<a href="{{site.github.repository_url}}/edit/{{ default_branch }}/{{page.path}}">Edit on GitHub</a>
3437
{% endif %}
3538
/
36-
<a href="{{ site.github.repository_url }}/blob/gh-pages/CONTRIBUTING.md">Contributing</a>
39+
<a href="{{ site.github.repository_url }}/blob/{{ site.github.source.branch }}/CONTRIBUTING.md">Contributing</a>
3740
/
3841
<a href="{{ site.github.repository_url }}/">Source</a>
3942
/
40-
<a href="{{ site.github.repository_url }}/blob/gh-pages/CITATION">Cite</a>
43+
<a href="{{ site.github.repository_url }}/blob/{{ site.github.source.branch }}/CITATION">Cite</a>
4144
/
4245
<a href="mailto:{{ site.email }}">Contact</a>
4346
</div>

_includes/navbar.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{% comment %}
22
Lesson navigation bar.
33
{% endcomment %}
4+
5+
{% include gh_default_branch.html %}
6+
47
<nav class="navbar navbar-default">
58
<div class="container-fluid">
69
<div class="navbar-header">
@@ -74,10 +77,10 @@
7477
<li><a href="{{ relative_root_path }}{% link LICENSE.md %}">License</a></li>
7578
{% if page.source %}
7679
{% if page.source == "Rmd" %}
77-
<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>
80+
<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>
7881
{% endif %}
7982
{% else %}
80-
<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>
83+
<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>
8184
{% endif %}
8285
</ul>
8386
<form class="navbar-form navbar-right" role="search" id="search" onsubmit="google_search(); return false;">

0 commit comments

Comments
 (0)