refactor to avoid errors when rendering locally
authorFrançois Michonneau <francois.michonneau@gmail.com>
Mon, 27 Aug 2018 14:53:54 +0000 (10:53 -0400)
committerFrançois Michonneau <francois.michonneau@gmail.com>
Tue, 11 Sep 2018 14:10:23 +0000 (10:10 -0400)
_includes/gh_default_branch.html [deleted file]
_includes/gh_variables.html [new file with mode: 0644]
_includes/lesson_footer.html
_includes/links.md
_includes/navbar.html
_layouts/base.html
_layouts/workshop.html

diff --git a/_includes/gh_default_branch.html b/_includes/gh_default_branch.html
deleted file mode 100644 (file)
index 5b6b77a..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-{% 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 %}
diff --git a/_includes/gh_variables.html b/_includes/gh_variables.html
new file mode 100644 (file)
index 0000000..e9c8f26
--- /dev/null
@@ -0,0 +1,45 @@
+{% comment %}
+When rendering websites locally, `site.github.url` doesn't get resolved
+properly unless GitHub PAT are set up and available in the environment.
+This leads to warnings and errors when trying to serve the site locally.
+To work around this, we use the `jekyll.environment` variable which is set to
+`development` when rendering the site locally, and set to `production` on
+GitHub where `site.github.url` will be defined.
+{% endcomment %}
+
+{% if jekyll.environment == "production" %}
+
+{% 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 %}
+Other variables requested by the template
+{% endcomment %}
+{% assign repo_url = site.github.repository_url %}
+{% assign search_domain_url = site.github.url %}
+{% assign project_title = site.github.project_title %}
+{% assign source_branch = site.github.source.branch %}
+
+{% elsif jekyll.environment == "development" %}
+
+{% assign repo_name = "" %}
+{% assign repo_url = "" %}
+{% assign default_branch = "" %}
+{% assign search_domain_url = "" %}
+{% assign project_title = "" %}
+{% assign source_branch = "" %}
+
+{% endif %}
index 330670b867cfd28df71aecbc613200e6e9961f8b..621243df9718ee4fde86134983b7b3b205b9bde9 100644 (file)
@@ -2,7 +2,7 @@
   Footer for lesson pages.
 {% endcomment %}
 
-{% include gh_default_branch.html %}
+{% include gh_variables.html %}
 
 <footer>
   <div class="row">
     <div class="col-md-6 help-links" align="right">
        {% if page.source %}
        {% if page.source == "Rmd" %}
-       <a href="{{site.github.repository_url}}/edit/{{ default_branch }}/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Edit on GitHub</a>
+       <a href="{{repo_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/{{ default_branch }}/{{page.path}}">Edit on GitHub</a>
+       <a href="{{repo_url}}/edit/{{ default_branch }}/{{page.path}}">Edit on GitHub</a>
        {% endif %}
        /
-       <a href="{{ site.github.repository_url }}/blob/{{ site.github.source.branch }}/CONTRIBUTING.md">Contributing</a>
+       <a href="{{ repo_url }}/blob/{{ source_branch }}/CONTRIBUTING.md">Contributing</a>
        /
-       <a href="{{ site.github.repository_url }}/">Source</a>
+       <a href="{{ repo_url }}/">Source</a>
        /
-       <a href="{{ site.github.repository_url }}/blob/{{ site.github.source.branch }}/CITATION">Cite</a>
+       <a href="{{ repo_url }}/blob/{{ source_branch }}/CITATION">Cite</a>
        /
        <a href="mailto:{{ site.email }}">Contact</a>
     </div>
index b5db6ab58cd75c02f6e7e7a7fc2eb1415db456b7..7244a1268fc5eb8b1a8d19aeb5e0ebeaacc6a3f1 100644 (file)
@@ -1,3 +1,5 @@
+{% include gh_variables.html %}
+
 [cc-by-human]: https://creativecommons.org/licenses/by/4.0/
 [cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode
 [ci]: http://communityin.org/
@@ -5,7 +7,7 @@
 [coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html
 [concept-maps]: https://carpentries.github.io/instructor-training/05-memory/
 [contrib-covenant]: https://contributor-covenant.org/
-[contributing]: {{ site.github.repository_url }}/blob/gh-pages/CONTRIBUTING.md
+[contributing]: {{ repo_url }}/blob/{{ source_branch }}/CONTRIBUTING.md
 [cran-checkpoint]: https://cran.r-project.org/package=checkpoint
 [cran-knitr]: https://cran.r-project.org/package=knitr
 [cran-stringr]: https://cran.r-project.org/package=stringr
index a9f1f075b77c3386044ecbc673a74f35a6442b0c..40939226fc1156f53efbfc6cef7a4a3a1d671dad 100644 (file)
@@ -2,7 +2,7 @@
   Lesson navigation bar.
 {% endcomment %}
 
-{% include gh_default_branch.html %}
+{% include gh_variables.html %}
 
 <nav class="navbar navbar-default">
   <div class="container-fluid">
         <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/{{ 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>
+       <li><a href="{{repo_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/{{ default_branch}}/{{page.path}}">Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
+       <li><a href="{{repo_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;">
index a083eb1f7bd8658f4f93d2bc5c3ba71ab7ac4c5d..34959d54a9b939ae4a44daf519689929849bbc78 100644 (file)
@@ -1,21 +1,7 @@
 ---
 ---
-{% comment %}
-When rendering websites locally, `site.github.url` doesn't get resolved
-properly unless GitHub PAT are set up and available in the environment.
-This leads to warnings and errors when trying to serve the site locally.
-To work around this, we use the `jekyll.environment` variable which is set to
-`development` when rendering the site locally, and set to `production` on
-GitHub where `site.github.url` will be defined.
-{% endcomment %}
-
-{% if jekyll.environment == "development" %}
-{% assign search_domain_url = "" %}
-{% elsif jekyll.environment == "production" %}
-{% assign search_domain_url = site.github.url  %}
-{% endif %}
-
 {% include base_path.html %}
+{% include gh_variables.html %}
 
 <!doctype html>
 <html lang="en">
index 9411e580c15e7c34ee639d7d42a924d153994bd5..cf57cdf4963c526c7b546fe8bbf2d4b938dc1fd2 100644 (file)
@@ -1,13 +1,13 @@
 ---
 ---
-
 {% include base_path.html %}
+{% include gh_variables.html %}
 
 <!doctype html>
 <html lang="en">
   <head>
 
-    <meta name="slug" content="{{site.github.project_title}}" />
+    <meta name="slug" content="{{project_title}}" />
     <meta name="startdate" content="{{page.startdate}}" />
     <meta name="enddate" content="{{page.enddate}}" />
     <meta name="humandate" content="{{page.humandate}}" />