From: François Michonneau Date: Mon, 27 Aug 2018 14:53:54 +0000 (-0400) Subject: refactor to avoid errors when rendering locally X-Git-Url: https://git.arvados.org/rnaseq-cwl-training.git/commitdiff_plain/d32a598f5ee2ff3d6f08c921a7ad35300e7181b2 refactor to avoid errors when rendering locally --- diff --git a/_includes/gh_default_branch.html b/_includes/gh_default_branch.html deleted file mode 100644 index 5b6b77a..0000000 --- a/_includes/gh_default_branch.html +++ /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 index 0000000..e9c8f26 --- /dev/null +++ b/_includes/gh_variables.html @@ -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 %} diff --git a/_includes/lesson_footer.html b/_includes/lesson_footer.html index 330670b..621243d 100644 --- a/_includes/lesson_footer.html +++ b/_includes/lesson_footer.html @@ -2,7 +2,7 @@ Footer for lesson pages. {% endcomment %} -{% include gh_default_branch.html %} +{% include gh_variables.html %}