Date formats are localized and i18n has simple macros

master
southerntofu 3 years ago
parent 56ca660bd7
commit 88dd168707
  1. 2
      config.toml
  2. 9
      templates/index.html
  3. 2
      templates/page.html
  4. 14
      templates/section.html
  5. 18
      templates/widgets.html

@ -29,8 +29,10 @@ source = "Source de cette page"
readmore = "Lire la suite"
previousPage = "Page précédente"
nextPage = "Page suivante"
dateFormat = "%d/%m/%Y"
[translations.en]
source = "Source for this page"
readmore = "Read more"
previousPage = "Previous page"
nextPage = "Next page"
dateFormat = "%m/%d/%Y"

@ -1,5 +1,5 @@
{% import "widgets.html" as widgets %}
{% set lang = section.lang | default(value=page.lang) %}{% if lang == "en" %}{% set lang = false %}{% endif %}
{% set lang = section.lang | default(value=page.lang) %}
<!DOCTYPE html>
<html class="no-js" lang="{{ lang | default(value="en")}}">
<head>
@ -14,9 +14,7 @@
<header>
{% set header = get_page(path="_common/header.md") %}
{{ header.content | markdown | safe }}
{% if lang %}{{ widgets::menu(content="_common/menu." ~ lang ~ ".md") }}
{% else %}{{ widgets::menu(content="_common/menu.md") }}
{% endif %}
{{ widgets::menu(content="_common/menu.md") }}
</header>
<main>
{% block main %}
@ -28,8 +26,7 @@
<footer>
{% if config.extra.forge %}
<aside class="source">
{% if lang %}{% set translated = trans(key="source", lang=lang) %}
{% else %}{% set translated = trans(key="source") %}{% endif %}
{% set translated = widgets::i18n(key="source") %}
{% if section %}
<a href="{{ config.extra.forge.browse }}content/{{ section.path }}_index.md">{{ translated }}</a>
{% else %}

@ -7,7 +7,7 @@
<div>
<h1 class="p-name">{{ page.title }}</h1>
<a class="u-url" hidden aria-hidden="true" href="{{ page.permalink }}">Permalink</a>
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format="%d/%m/%Y") }}</time>{%- endif -%}
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=widgets::i18n(key="dateFormat")) }}</time>{%- endif -%}
</div>
<div class="e-content">{{ page.content | safe }}</div>
</article>

@ -11,12 +11,12 @@
<article>
<div>
<a class="u-url" href="{{ page.permalink }}"><h2>{{ page.title }}</h2></a>
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format="%d/%m/%Y") }}</time>{%- endif -%}
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=widgets::i18n(key="dateFormat")) }}</time>{%- endif -%}
</div>
{% if page.summary %}
<div class="p-summary e-content">
{{ page.summary | markdown | safe }}
<a class="read-more" href="{{ page.permalink }}">--> {% if lang %}{{ trans(key="readmore", lang=lang) }}{% else %}{{ trans(key="readmore") }}{% endif %} <--</a>
<a class="read-more" href="{{ page.permalink }}">--> {{ widgets::i18n(key="readmore") }} <--</a>
</div>
{% else %}
<div class="e-content">
@ -28,16 +28,10 @@
{% if paginator and paginator.number_pagers > 1 %}
<aside class="pagination">
{% if paginator.previous %}
<a href="{{ paginator.previous }}">
<--&nbsp;&nbsp;{% if lang %}{{ trans(key="previousPage", lang=lang) }}
{% else %}{{ trans(key="previousPage") }}{% endif %}
</a>
<a href="{{ paginator.previous }}"><--&nbsp;&nbsp;{{ widgets::i18n(key="previousPage") }}</a>
{% endif %}
{% if paginator.next %}
<a href="{{ paginator.next }}">
{% if lang %}{{ trans(key="nextPage", lang=lang) }}
{% else %}{{ trans(key="nextPage") }}{% endif %}&nbsp;&nbsp;-->
</a>
<a href="{{ paginator.next }}">{{ widgets::i18n(key="nextPage") }}&nbsp;&nbsp;--></a>
{% endif %}
</aside>
{% endif %}

@ -17,9 +17,25 @@ a submenu. A submenu is an actual list
######################################}
{% macro menu(content) %}
<nav class="nav-menu" role="navigation">
{%- set source = get_page(path=content) %}{% set entries = source.content | split(pat="<hr />") %}{# fetch page content and divide it with separator -#}
{%- set source = get_page(path=self::i18n_page(page=content)) %}{% set entries = source.content | split(pat="<hr />") %}{# fetch page content and divide it with separator -#}
{%- for entry in entries %}
{{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}{# strip paragraph tags away for nicer markup #}
{%- endfor %}
</nav>
{% endmacro menu %}
{%- macro i18n(key) -%}
{{ trans(key=key, lang=lang) }}
{%- endmacro i18n -%}
{%- macro i18n_page(page) -%}
{% if lang == "en" %}{{ page }}
{%- else -%}
{%- set parts = page | split(pat=".md") -%}
{%- for part in parts -%}
{%- if part and not loop.first -%}.md{%- endif -%}
{%- if not loop.last -%}{{ part }}{%- endif -%}
{%- endfor -%}
.{{ lang }}.md
{%- endif -%}
{%- endmacro i18n_page -%}

Loading…
Cancel
Save