Skip to content

Commit 55695c4

Browse files
committed
Merge branch 'fix-gh-edit-links' of github.com:carpentries/styles
2 parents f7fe1f7 + 7bc76f8 commit 55695c4

File tree

6 files changed

+60
-27
lines changed

6 files changed

+60
-27
lines changed

_includes/gh_variables.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{% comment %}
2+
When rendering websites locally, `site.github.url` doesn't get resolved
3+
properly unless GitHub PAT are set up and available in the environment.
4+
This leads to warnings and errors when trying to serve the site locally.
5+
To work around this, we use the `jekyll.environment` variable which is set to
6+
`development` when rendering the site locally, and set to `production` on
7+
GitHub where `site.github.url` will be defined.
8+
{% endcomment %}
9+
10+
{% if jekyll.environment == "production" %}
11+
12+
{% comment %}
13+
First, get the name of the repository
14+
{% endcomment %}
15+
{% assign repo_name = site.github.repository_name %}
16+
17+
{% comment %}
18+
`site.github.public_repositories` contains comprehensive information for all public repositories for the organization. We use `where` to extract the part
19+
of the metadata that is relevant to the present repository.
20+
{% endcomment %}
21+
{% assign repo_info = site.github.public_repositories | where: "name", repo_name %}
22+
23+
{% comment %}
24+
Now, we can extract the default branch for the repo
25+
{% endcomment %}
26+
{% assign default_branch = repo_info[0].default_branch %}
27+
28+
{% comment %}
29+
Other variables requested by the template
30+
{% endcomment %}
31+
{% assign repo_url = site.github.repository_url %}
32+
{% assign search_domain_url = site.github.url %}
33+
{% assign project_title = site.github.project_title %}
34+
{% assign source_branch = site.github.source.branch %}
35+
36+
{% elsif jekyll.environment == "development" %}
37+
38+
{% assign repo_name = "" %}
39+
{% assign repo_url = "" %}
40+
{% assign default_branch = "" %}
41+
{% assign search_domain_url = "" %}
42+
{% assign project_title = "" %}
43+
{% assign source_branch = "" %}
44+
45+
{% endif %}

_includes/lesson_footer.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Footer for lesson pages.
33
{% endcomment %}
44

5-
{% include gh_default_branch.html %}
5+
{% include gh_variables.html %}
66

77
<footer>
88
<div class="row">
@@ -30,17 +30,17 @@
3030
<div class="col-md-6 help-links" align="right">
3131
{% if page.source %}
3232
{% if page.source == "Rmd" %}
33-
<a href="{{site.github.repository_url}}/edit/{{ default_branch }}/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Edit on GitHub</a>
33+
<a href="{{repo_url}}/edit/{{ default_branch }}/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">Edit on GitHub</a>
3434
{% endif %}
3535
{% else %}
36-
<a href="{{site.github.repository_url}}/edit/{{ default_branch }}/{{page.path}}">Edit on GitHub</a>
36+
<a href="{{repo_url}}/edit/{{ default_branch }}/{{page.path}}">Edit on GitHub</a>
3737
{% endif %}
3838
/
39-
<a href="{{ site.github.repository_url }}/blob/{{ site.github.source.branch }}/CONTRIBUTING.md">Contributing</a>
39+
<a href="{{ repo_url }}/blob/{{ source_branch }}/CONTRIBUTING.md">Contributing</a>
4040
/
41-
<a href="{{ site.github.repository_url }}/">Source</a>
41+
<a href="{{ repo_url }}/">Source</a>
4242
/
43-
<a href="{{ site.github.repository_url }}/blob/{{ site.github.source.branch }}/CITATION">Cite</a>
43+
<a href="{{ repo_url }}/blob/{{ source_branch }}/CITATION">Cite</a>
4444
/
4545
<a href="mailto:{{ site.email }}">Contact</a>
4646
</div>

_includes/links.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
{% include gh_variables.html %}
2+
13
[cc-by-human]: https://creativecommons.org/licenses/by/4.0/
24
[cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode
35
[ci]: http://communityin.org/
46
[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html#reporting-guidelines
57
[coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html
68
[concept-maps]: https://carpentries.github.io/instructor-training/05-memory/
79
[contrib-covenant]: https://contributor-covenant.org/
8-
[contributing]: {{ site.github.repository_url }}/blob/gh-pages/CONTRIBUTING.md
10+
[contributing]: {{ repo_url }}/blob/{{ source_branch }}/CONTRIBUTING.md
911
[cran-checkpoint]: https://cran.r-project.org/package=checkpoint
1012
[cran-knitr]: https://cran.r-project.org/package=knitr
1113
[cran-stringr]: https://cran.r-project.org/package=stringr

_includes/navbar.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Lesson navigation bar.
33
{% endcomment %}
44

5-
{% include gh_default_branch.html %}
5+
{% include gh_variables.html %}
66

77
<nav class="navbar navbar-default">
88
<div class="container-fluid">
@@ -77,10 +77,10 @@
7777
<li><a href="{{ relative_root_path }}{% link LICENSE.md %}">License</a></li>
7878
{% if page.source %}
7979
{% if page.source == "Rmd" %}
80-
<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>
80+
<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>
8181
{% endif %}
8282
{% else %}
83-
<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>
83+
<li><a href="{{repo_url}}/edit/{{ default_branch}}/{{page.path}}">Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
8484
{% endif %}
8585
</ul>
8686
<form class="navbar-form navbar-right" role="search" id="search" onsubmit="google_search(); return false;">

_layouts/base.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
---
22
---
3-
{% comment %}
4-
When rendering websites locally, `site.github.url` doesn't get resolved
5-
properly unless GitHub PAT are set up and available in the environment.
6-
This leads to warnings and errors when trying to serve the site locally.
7-
To work around this, we use the `jekyll.environment` variable which is set to
8-
`development` when rendering the site locally, and set to `production` on
9-
GitHub where `site.github.url` will be defined.
10-
{% endcomment %}
11-
12-
{% if jekyll.environment == "development" %}
13-
{% assign search_domain_url = "" %}
14-
{% elsif jekyll.environment == "production" %}
15-
{% assign search_domain_url = site.github.url %}
16-
{% endif %}
17-
183
{% include base_path.html %}
4+
{% include gh_variables.html %}
195

206
<!doctype html>
217
<html lang="en">

_layouts/workshop.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
---
3-
43
{% include base_path.html %}
4+
{% include gh_variables.html %}
55

66
<!doctype html>
77
<html lang="en">
88
<head>
99

10-
<meta name="slug" content="{{site.github.project_title}}" />
10+
<meta name="slug" content="{{project_title}}" />
1111
<meta name="startdate" content="{{page.startdate}}" />
1212
<meta name="enddate" content="{{page.enddate}}" />
1313
<meta name="humandate" content="{{page.humandate}}" />

0 commit comments

Comments
 (0)