use github metadata to identify branch to use when editing files
authorFrançois Michonneau <francois.michonneau@gmail.com>
Fri, 24 Aug 2018 21:33:33 +0000 (17:33 -0400)
committerFrançois Michonneau <francois.michonneau@gmail.com>
Tue, 11 Sep 2018 14:10:23 +0000 (10:10 -0400)
_includes/gh_default_branch.html [new file with mode: 0644]
_includes/lesson_footer.html
_includes/navbar.html

diff --git a/_includes/gh_default_branch.html b/_includes/gh_default_branch.html
new file mode 100644 (file)
index 0000000..5b6b77a
--- /dev/null
@@ -0,0 +1,19 @@
+{% 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 %}
index 9606a31e0cc013137cf3336742dab3e47971e342..330670b867cfd28df71aecbc613200e6e9961f8b 100644 (file)
@@ -1,6 +1,9 @@
 {% comment %}
   Footer for lesson pages.
 {% endcomment %}
+
+{% include gh_default_branch.html %}
+
 <footer>
   <div class="row">
     <div class="col-md-6 copyright" align="left">
     <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>
index 529a83c63979c6ae4c05b6c06bc30dff2268d4f2..a9f1f075b77c3386044ecbc673a74f35a6442b0c 100644 (file)
@@ -1,6 +1,9 @@
 {% comment %}
   Lesson navigation bar.
 {% endcomment %}
+
+{% include gh_default_branch.html %}
+
 <nav class="navbar navbar-default">
   <div class="container-fluid">
     <div class="navbar-header">
         <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;">