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

refactor to avoid errors when rendering locally

parent feeb525b
{% comment %}
identify the default branch of the GitHub repo for the lesson, to create the correct link for "Improve on GitHub"
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 %}
......@@ -17,3 +24,22 @@ of the metadata that is relevant to the present repository.
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 %}
......@@ -2,7 +2,7 @@
Footer for lesson pages.
{% endcomment %}
{% include gh_default_branch.html %}
{% include gh_variables.html %}
<footer>
<div class="row">
......@@ -30,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/{{ 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>
......
{% 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
......
......@@ -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">
......@@ -77,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/{{ 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;">
......
---
---
{% 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">
......
---
---
{% 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}}" />
......
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