Skip to content

Commit

Permalink
refactor to avoid errors when rendering locally
Browse files Browse the repository at this point in the history
  • Loading branch information
fmichonneau committed Sep 11, 2018
1 parent feeb525 commit d32a598
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 46 deletions.
19 changes: 0 additions & 19 deletions _includes/gh_default_branch.html

This file was deleted.

45 changes: 45 additions & 0 deletions _includes/gh_variables.html
Original file line number Diff line number Diff line change
@@ -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 %}
12 changes: 6 additions & 6 deletions _includes/lesson_footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Footer for lesson pages.
{% endcomment %}

{% include gh_default_branch.html %}
{% include gh_variables.html %}

<footer>
<div class="row">
Expand Down Expand Up @@ -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>
Expand Down
4 changes: 3 additions & 1 deletion _includes/links.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{% 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/
[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html#reporting-guidelines
[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
Expand Down
6 changes: 3 additions & 3 deletions _includes/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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;">
Expand Down
16 changes: 1 addition & 15 deletions _layouts/base.html
Original file line number Diff line number Diff line change
@@ -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">
Expand Down
4 changes: 2 additions & 2 deletions _layouts/workshop.html
Original file line number Diff line number Diff line change
@@ -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}}" />
Expand Down

0 comments on commit d32a598

Please sign in to comment.