Skip to content

Commit

Permalink
Set all tokens and translations links for base layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dpshelio committed Aug 8, 2019
1 parent 9028548 commit 7953c24
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 30 deletions.
14 changes: 7 additions & 7 deletions _includes/lesson_footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
<div class="col-md-6 help-links" align="right">
{% if page.source %}
{% if page.source == "Rmd" %}
<a href="{{repo_url}}/edit/{{ default_branch }}/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}" data-checker-ignore>Edit on GitHub</a>
{% endif %}
<a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">{{ include.language.edit }}</a>
{% endif %}
{% else %}
<a href="{{repo_url}}/edit/{{ default_branch }}/{{page.path}}" data-checker-ignore>Edit on GitHub</a>
<a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path}}">{{ include.language.edit }}</a>
{% endif %}
/
<a href="{{ repo_url }}/blob/{{ source_branch }}/CONTRIBUTING.md" data-checker-ignore>Contributing</a>
<a href="{{ site.github.repository_url }}/blob/gh-pages/CONTRIBUTING.md">{{ include.language.contribute }}</a>
/
<a href="{{ repo_url }}/">Source</a>
<a href="{{ site.github.repository_url }}/">{{ include.language.source }}</a>
/
<a href="{{ repo_url }}/blob/{{ source_branch }}/CITATION" data-checker-ignore>Cite</a>
<a href="{{ site.github.repository_url }}/blob/gh-pages/CITATION">{{ include.language.cite }}</a><!-- FIXME: cite the lesson or the translation? -->
/
<a href="mailto:{{ site.email }}">Contact</a>
<a href="mailto:{{ site.email }}">{{ include.language.contact }}</a>
</div>
</div>
<div class="row">
Expand Down
78 changes: 63 additions & 15 deletions _includes/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,58 +34,106 @@
{% endif %}

{% comment %} Always show link to home page. {% endcomment %}
<a class="navbar-brand" href="{{ relative_root_path }}{% link index.md %}">Home</a>
<a class="navbar-brand" href="{{ page.root }}{% link index.md %}">{{ include.language.index }}</a>

</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">

{% comment %} Always show code of conduct. {% endcomment %}
<li><a href="{{ relative_root_path }}{% link CODE_OF_CONDUCT.md %}">Code of Conduct</a></li>
<li><a href="{{ page.root }}{% link CONDUCT.md %}">{{ include.language.CoC }}</a></li>

{% if site.kind == "lesson" %}
{% comment %} Show setup instructions. {% endcomment %}
<li><a href="{{ relative_root_path }}{% link setup.md %}">Setup</a></li>
<li><a href="{{ page.root }}{% link setup.md %}">{{ include.language.setup }}</a></li>

{% comment %} Show lesson episodes for lessons. {% endcomment %}
<li class="dropdown">
<a href="{{ relative_root_path }}/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Episodes <span class="caret"></span></a>
<a href="{{ page.root }}/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ include.language.episodes }} <span class="caret"></span></a>
<ul class="dropdown-menu">
{% for episode in site.episodes %}
<li><a href="{{ relative_root_path }}{{ episode.url }}">{{ episode.title }}</a></li>
{% for episode in episodes %}
<li><a href="{{ episode.url }}">{{ episode.title }}</a></li><!-- NOTE: Check whether this works on github where root is different than localhost; also for extras and others. -->
{% endfor %}
<li role="separator" class="divider"></li>
<li><a href="{{ relative_root_path }}{% link aio.md %}">All in one page (Beta)</a></li>
<li><a href="{{ page.root }}{% link aio.md %}">{{ include.language.aio }} (Beta)</a></li>
</ul>
</li>
{% endif %}

{% comment %} Show extras for lessons or if this is the main workshop-template repo (where they contain documentation). {% endcomment %}
{% if site.kind == "lesson" %}
<li class="dropdown">
<a href="{{ relative_root_path }}/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Extras <span class="caret"></span></a>
<a href="{{ page.root }}/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ include.language.extras }} <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="{{ relative_root_path }}{% link reference.md %}">Reference</a></li>
{% for extra in site.extras %}
<li><a href="{{ relative_root_path }}{{ extra.url }}">{{ extra.title }}</a></li>
<li><a href="{{ page.root }}{% link reference.md %}">{{ include.language.reference }}</a></li>
{% for extra in extras %}
<li><a href="{{ extra.url }}">{{ extra.title }}</a></li>
{% endfor %}
</ul>
</li>
{% endif %}

{% comment %} Always show license. {% endcomment %}
<li><a href="{{ relative_root_path }}{% link LICENSE.md %}">License</a></li>
<li><a href="{{ page.root }}{% link LICENSE.md %}">{{ include.language.LICENSE }}</a></li>
{% if page.source %}
{% if page.source == "Rmd" %}
<li><a href="{{repo_url}}/edit/{{ default_branch }}/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}" data-checker-ignore>Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
<li><a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path|replace: "_episodes", "_episodes_rmd" | replace: ".md", ".Rmd"}}">{{ include.language.improve }}<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
{% endif %}
{% else %}
<li><a href="{{repo_url}}/edit/{{ default_branch}}/{{page.path}}" data-checker-ignore>Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
<li><a href="{{site.github.repository_url}}/edit/gh-pages/{{page.path}}">{{ include.language.improve }}<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
{% endif %}

{% comment %} Adding languages if they exists {% endcomment %}
{% if site.kind == "lesson" and site.locale %}
<li class="dropdown">
<a href="{{ page.root }}/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-globe" aria-hidden="true"></span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
{% assign current_page = page.path | split: "/" | last %}
{% if page.path contains "locale" %}
{% comment %} Check whether the page is a root page {% endcomment %}
{% assign allpages = site.pages | map: "path" %}
{% if allpages contains current_page %}
{% assign path_current = site.pages | where_exp: "spage", "spage.path contains current_page" | map: "url" %}
{% assign path_word = current_page | replace: ".md", "" %}
<li><a href="{{ path_current }}">en: {{ include.language_en[path_word] }}</a>
{% else %}
{% comment %} Looking for episodes {% endcomment %}
{% for episode in site.episodes %}
{% capture original_episode %}{{ episode.path | split: "/" | last }}{% endcapture %}
{% if original_episode == current_page %}
<li><a href="{{ episode.url }}">en: {{ episode.title }}</a>
{% endif %}
{% endfor %}
{% comment %} Looking for extras {% endcomment %}
{% for extra in site.extras %}
{% capture original_extra %}{{ extra.path | split: "/" | last }}{% endcapture %}
{% if original_extra == current_page %}
<li><a href="{{ extra.url }}">en: {{ extra.title }}</a>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% comment %} Generate the links for the other possible translations {% endcomment %}
{% for translated_page in site.locale %}
{% if translated_page.path != page.path %} {% comment %} to skip the current page {% endcomment %}
{% assign langfilename = translated_page.path | split: "/" | last %}
{% assign thislanguage = translated_page.path | remove: "_locale/" | split: "/" | first %}
{% if page.path contains langfilename %} {% comment %} So it's the translation of the page {% endcomment %}
<li><a href="{{ translated_page.url }}">{{ thislanguage }}: {{ translated_page.title}}</a></li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
</li>
{% endif %}

</ul>
<form class="navbar-form navbar-right" role="search" id="search" onsubmit="google_search(); return false;">
<div class="form-group">
<input type="text" id="google-search" placeholder="Search..." aria-label="Google site search">
<input type="text" id="google-search" placeholder="{{ include.language.search }}..." aria-label="Google site search">
</div>
</form>
</div>
Expand Down
24 changes: 21 additions & 3 deletions _layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@
{% include base_path.html %}
{% include gh_variables.html %}

{% comment %}
In which language is the current page? Guess from the path: locale="/<lang>/".
Load language tockens for menus {{ data_language }}. Translations need to provide a lang.md file that translates what's under _data/language.yaml
Generate list of episodes and extras for the language shown. - NOTE: _extras need in the permlinks /<language>/page!!
{% endcomment %}
{% if page.path contains "_locale" %}
{% assign locale = page.path | remove: "_locale/" | split: "/" | first | downcase %}
{% assign pathLocale = locale | append: '/' | prepend: '/' %}
{% assign episodes = site.locale | where_exp:"item", "item.path contains pathLocale" | where_exp:"item", "item.path contains 'episode'" | sort: "path" %}
{% assign extras = site.locale | where_exp:"item", "item.path contains pathLocale" | where_exp:"item", "item.path contains 'extra'" | sort: "path" %}
{% else %}
{% assign locale = "en" %}
{% assign episodes = site.episodes %}
{% assign extras = site.extras %}
{% endif %}
{% assign lang_file = locale | append: '.md' %}
{% assign data_language = site.pages | where_exp:"page", "page.path contains 'i18n'" | where_exp:"page", "page.path contains lang_file" | first %}
{% assign data_language_en = site.pages | where_exp:"page", "page.path contains 'i18n'" | where_exp:"page", "page.path contains 'en.md'" | first %}
<!doctype html>
<html lang="en">
<html lang="{{ locale }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand Down Expand Up @@ -35,12 +53,12 @@
{% include life_cycle.html %}

<div class="container">
{% include navbar.html %}
{% include navbar.html language=data_language language_en=data_language_en episodes=episodes extras=extras locale=locale %}
{{ content }}
{% if site.kind == "workshop" %}
{% include workshop_footer.html %}
{% else %}
{% include lesson_footer.html %}
{% include lesson_footer.html language=data_language %}
{% endif %}
</div>
{% include javascript.html %}
Expand Down
4 changes: 2 additions & 2 deletions assets/i18n/en.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
home: "Home"
index: "Home"
CoC: "Code of Conduct"
setup: "Setup"
episodes: "Episodes"
extras: "Extras"
license: "License"
LICENSE: "License"
improve: "Improve this page"
reference: "Reference"
aio: "All in One"
Expand Down
6 changes: 3 additions & 3 deletions assets/i18n/es.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
home: Inicio
CoC: Codigo de Conducta
index: Inicio
CoC: Código de Conducta
setup: Configuración
episodes: Episodes
extras: Extras
license: Licencia
LICENSE: Licencia
improve: Mejora esta página
reference: Referencias
aio: Todo en uno
Expand Down

0 comments on commit 7953c24

Please sign in to comment.