Skip to content
Permalink
Browse files

refactor to avoid errors when rendering locally

  • Loading branch information...
fmichonneau committed Aug 27, 2018
1 parent 06ad1c0 commit 7bc76f80907cc79a03856be9babc98fe2367f2dd

This file was deleted.

@@ -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 %}
@@ -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>
@@ -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
@@ -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;">
@@ -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">
@@ -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}}" />

0 comments on commit 7bc76f8

Please sign in to comment.
You can’t perform that action at this time.