Initial work on adding i18n support, drop footer link support (breaking change!)

This commit is contained in:
daudix
2024-06-15 22:36:03 +03:00
parent c1f9247c86
commit a4a68c8b61
25 changed files with 821 additions and 100 deletions

View File

@ -11,7 +11,7 @@
</time>
{%- if page.authors %}
<span></span>
<span>Author: {{ page.authors[0] }}</span>
<span>{{ trans(key="author", default="Author", lang=lang) }}: {{ page.authors[0] }}</span>
{%- endif %}
{%- if page.taxonomies %}
{%- for name, taxon in page.taxonomies %}
@ -19,7 +19,7 @@
<ul class="tags">
{%-for item in taxon %}
<li>
<a class="tag" href="{{ get_taxonomy_url(kind=name, name=item) }}">{{ item }}</a>
<a class="tag" href="{{ get_taxonomy_url(kind=name, name=item, lang=lang) }}">{{ item }}</a>
</li>
{%- endfor %}
</ul>
@ -32,7 +32,7 @@
<div class="statement-container archive">
<strong class="big">
<i class="icon"></i>
Archived
{{ trans(key="archived", default="Archived", lang=lang) }}
</strong>
{{ page.extra.archive | markdown | safe }}
</div>
@ -42,7 +42,7 @@
<div class="statement-container trigger">
<strong class="big">
<i class="icon"></i>
Trigger Warning
{{ trans(key="trigger_warning", default="Trigger Warning", lang=lang) }}
</strong>
{{ page.extra.trigger | markdown | safe }}
</div>
@ -52,14 +52,14 @@
<div class="statement-container disclaimer">
<strong class="big">
<i class="icon"></i>
Disclaimer
{{ trans(key="disclaimer", default="Disclaimer", lang=lang) }}
</strong>
{{ page.extra.disclaimer | markdown | safe }}
</div>
{% endif %}
{% if page.extra.toc %}
<h2>Table of Contents</h2>
<h2>{{ trans(key="table_of_contents", default="Table of Contents", lang=lang) }}</h2>
<ul>
{% for h1 in page.toc %}
<li>
@ -82,7 +82,7 @@
</article>
{% if page.extra.comments.id %}
{% include "partials/comments.html" %}
{% include "partials/comments.html" ignore missing %}
{% endif %}
{% if page.lower or page.higher %}
@ -90,13 +90,13 @@
<nav id="post-nav">
{% if page.higher %}
<a class="post-nav-item post-nav-prev" href="{{ page.higher.permalink }}">
<div class="nav-arrow">Previous</div>
<div class="nav-arrow">{{ trans(key="page_previous", default="Previous", lang=lang) }}</div>
<span class="post-title">{{ page.higher.title }}</span>
</a>
{% endif %}
{% if page.lower %}
<a class="post-nav-item post-nav-next" href="{{ page.lower.permalink }}">
<div class="nav-arrow">Next</div>
<div class="nav-arrow">{{ trans(key="page_next", default="Next", lang=lang) }}</div>
<span class="post-title">{{ page.lower.title }}</span>
</a>
{% endif %}
@ -104,9 +104,9 @@
{% endif %}
<div class="dialog-buttons">
<a class="inline-button" href="#top">Go to Top</a>
<a class="inline-button" href="#top">{{ trans(key="go_to_top", default="Go to Top", lang=lang) }}</a>
{% if config.extra.issues_url %}
<a class="inline-button colored" href="{{ config.extra.issues_url }}">File an Issue</a>
<a class="inline-button colored" href="{{ config.extra.issues_url }}">{{ trans(key="file_an_issue", default="File an Issue", lang=lang) }}</a>
{% endif %}
</div>
{% endblock content %}

View File

@ -6,9 +6,9 @@
{{ section.description | markdown | safe }}
<small>
<a class="link-page" href="{{ get_url(path='tags') }}">Filter by tag</a>
<a class="link-page" href="{{ get_url(path='tags', lang=lang) }}">{{ trans(key="filter_by_tag", default="Filter by tag", lang=lang) }}</a>
<br />
From newest to oldest ↓
{{ trans(key="newest_to_oldest", default="From newest to oldest", lang=lang) }}
</small>
<div id="article-list">
@ -18,13 +18,13 @@
{%- if page.draft %}
<span class="draft-badge">
<i class="icon"></i>
Drafted
{{ trans(key="drafted", default="Drafted", lang=lang) }}
</span>
{%- endif %}
{%- if page.extra.archive %}
<span class="archive-badge">
<i class="icon"></i>
Archived
{{ trans(key="archived", default="Archived", lang=lang) }}
</span>
{%- endif %}
{%- if page.description %}
@ -35,14 +35,14 @@
<time datetime="{{ page.date | date(format='%+') }}" pubdate>{{- page.date | date(format=config.extra.date_format) -}}</time>
{%- if page.authors %}
<span></span>
<span>Author: {{ page.authors[0] }}</span>
<span>{{ trans(key="author", default="Author", lang=lang) }}: {{ page.authors[0] }}</span>
{%- endif %}
{%- if page.taxonomies %}
{%- for name, taxon in page.taxonomies %}
<span></span>
<ul class="tags">
{%-for item in taxon %}
<li><a class="tag" href="{{ get_taxonomy_url(kind=name, name=item) }}">{{ item }}</a></li>
<li><a class="tag" href="{{ get_taxonomy_url(kind=name, name=item, lang=lang) }}">{{ item }}</a></li>
{%- endfor %}
</ul>
{%- endfor %}

View File

@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en">
{% include "partials/head.html" -%}
{% include "partials/head.html" ignore missing %}
<body>
{% include "partials/nav.html" -%}
{% include "partials/nav.html" ignore missing %}
<div id="main" class="container">
{% block custom %}{%- endblock -%}
{% block content %}{%- endblock -%}
</div>
{% include "partials/footer.html" -%}
{% include "partials/footer.html" ignore missing %}
</body>
</html>

View File

@ -5,7 +5,7 @@
<div class="statement-container archive">
<strong class="big">
<i class="icon"></i>
Archived
{{ trans(key="archived", default="Archived", lang=lang) }}
</strong>
{{ page.extra.archive | markdown | safe }}
</div>

View File

@ -13,31 +13,23 @@
{% endif %}
{% set id = page.extra.comments.id %}
{% set post_url = "https://{{ host }}/@{{ username }}/{{ id }}" %}
<section id="comments">
{% if config.extra.comments.show_qr %}
<img id="qrcode" class="no-hover pixels" alt="QR code to a Mastodon post" src="https://api.qrserver.com/v1/create-qr-code/?data=https://{{ host }}/@{{ username }}/{{ id }}&format=gif" />
<img id="qrcode" class="no-hover pixels" alt="QR code to a Mastodon post" src="https://api.qrserver.com/v1/create-qr-code/?data={{ post_url }}&format=gif" />
{% endif %}
<h2>Comments</h2>
<p>
You can comment on this blog post by publicly replying to this <a href="https://{{ host }}/@{{ username }}/{{ id }}">post</a> using a Mastodon or other ActivityPub/Fediverse account. Known non-private replies are displayed below.
</p>
<h2>{{ trans(key="comments", default="Comments", lang=lang) }}</h2>
<p>{{ trans(key="comments_description", default="You can comment on this blog post by publicly replying to this post using a Mastodon or other ActivityPub/Fediverse account. Known non-private replies are displayed below.", lang=lang) }}</p>
<p>
<a id="load-comments" class="inline-button" onclick="loadComments()" onkeypress="loadComments()" tabindex="0">Load Comments</a>
<a id="load-comments" class="inline-button" onclick="loadComments()" onkeypress="loadComments()" tabindex="0">{{ trans(key="load_comments", default="Load Comments", lang=lang) }}</a>
</p>
<div id="comments-wrapper">
<noscript>
<p>
Loading comments relies on JavaScript. Try enabling JavaScript and
reloading, or visit
<a href="https://{{ host }}/@{{ username }}/{{ id }}">
the original post
</a>
on Mastodon.
</p>
<p>{{ trans(key="comments_noscript", default="Loading comments relies on JavaScript. Try enabling JavaScript and reloading, or visit the original post on Mastodon.", lang=lang) }}</p>
</noscript>
</div>
<script type="text/javascript">
@ -76,7 +68,7 @@
function loadComments() {
let commentsWrapper = document.getElementById("comments-wrapper");
document.getElementById("load-comments").innerHTML = "Loading…";
document.getElementById("load-comments").innerHTML = "{{ trans(key='comments_loading', default='Loading…', lang=lang) }}";
fetch("https://{{ host }}/api/v1/statuses/{{ id }}/context")
.then(function (response) {
return response.json();

View File

@ -1,36 +1,18 @@
<footer id="site-footer">
{% if config.extra.footer.links %}
<nav>
<ul id="links">
{% for link in config.extra.footer.links %}
{%- if link.url is matching('https?://') %}
<li>
<a href="{{ link.url | safe }}">{{ link.name }}</a>
</li>
{%- else %}
<li>
<a href="{{ get_url(path=link.url | safe )}}">{{ link.name }}</a>
</li>
{%- endif %}
{% endfor %}
</ul>
</nav>
{% endif %}
{% if config.extra.footer.show_copyright %}
<p title="Last built at {{ now() | date(format='%F %a %R') }}">&copy; {{ config.title }}, {{ now() | date(format="%Y") }}</p>
{% endif %}
{% if config.extra.source_url and config.extra.footer.show_source %}
<p>
<a href="{{ config.extra.source_url | safe }}">Website source</a>
<a href="{{ config.extra.source_url }}">{{ trans(key='footer_source', default="Website source", lang=lang) }}</a>
</p>
{% endif %}
{% if config.extra.footer.show_powered_by %}
<p>
<small>
Powered by <a href="https://www.getzola.org">Zola</a> and <a href="https://daudix.codeberg.page/duckquill">Duckquill</a>
{{ trans(key="footer_powered_by", default="Powered by", lang=lang) }} <a href="https://www.getzola.org">Zola</a> {{ trans(key="footer_powered_by_and", default="and", lang=lang) }} <a href="https://daudix.codeberg.page/duckquill">Duckquill</a>
</small>
</p>
{% endif %}

View File

@ -6,20 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="{{ config.extra.primary_color }}" />
<link rel="canonical" href="{{ current_url | default(value='/') | safe }}" />
<title>
{%- if page.title -%}
{{- page.title }} - {{ config.title -}}
{%- elif section.title -%}
{{- section.title }} - {{ config.title -}}
{%- else -%}
{{- config.title -}}
{%- endif -%}
</title>
<title>{% block title %}{% include "partials/title.html" ignore missing %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{{ get_url(path='style.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ get_url(path='syntax-theme-dark.css') }}" media="(prefers-color-scheme: dark)" />
<link rel="stylesheet" type="text/css" href="{{ get_url(path='syntax-theme-light.css') }}" media="(prefers-color-scheme: light)" />
{% if config.extra.stylesheets %}
{% for stylesheet in config.extra.stylesheets %}
<link rel="stylesheet" type="text/css" href="{{ get_url(path=stylesheet) }}" />
@ -51,6 +42,7 @@
{% if config.extra.comments %}
<link rel="me" href="https://{{ config.extra.comments.host }}/@{{ config.extra.comments.user }}" />
{% endif %}
{% if config.extra.emoji_favicon %}
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ctext x='-.07em' y='.89em' font-size='90'%3E{{ config.extra.emoji_favicon }}%3C/text%3E%3C/svg%3E">
{% elif config.extra.animated_favicon %}
@ -58,10 +50,18 @@
{% else %}
<link rel="icon" type="image/png" href="{{ get_url(path='favicon.png') }}" />
{% endif %}
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="{{ get_url(path='apple-touch-icon.png') }}" />
{% if config.generate_feed %}
{% block feed -%}
<link rel="alternate" type={% if config.feed_filename == "atom.xml" %}"application/atom+xml"{% else %}"application/rss+xml"{% endif %} title="{{ config.title }}" href="{{ get_url(path=config.feed_filename) | safe }}">
{% endblock -%}
{% endif %}
<!-- Open Graph -->
<meta property="og:site_name" content="{{ config.title }}" />
<meta property="og:title" content="{%- if page.title -%}{{- page.title }} - {{ config.title -}}{%- elif section.title -%}{{- section.title }} - {{ config.title -}}{%- else -%}{{- config.title -}}{%- endif -%}" />
<meta property="og:title" content="{% include 'partials/title.html' ignore missing %}" />
<meta property="og:url" content="{{ current_url | default(value='/') | safe }}" />
<meta property="og:description" content="{{ page.description | default(value=config.description) }}" />
<meta property="og:image" content="{{ get_url(path='card.png') }}" />

View File

@ -0,0 +1,12 @@
{% if config.extra.language_switcher %}
<div class="lang" aria-label="{{ trans(key="language", lang=lang) }}">
{% set language_agnostic_path = current_path | default(value="/") | replace(from='/' ~ lang ~ '/', to = '/') | trim_start_matches(pat = '/') %}
{% for tr in config.extra.translations %}
{% if tr.code == lang %}
<span class="active">{{ tr.name }}</span>
{% else %}
<a href="{{ get_url(path=language_agnostic_path, lang=tr.code) ~ "/" }}" hreflang="{{ tr.code }}" lang="{{ tr.code }}">{{ tr.name }}</a>
{% endif %}
{% endfor %}
</div>
{% endif %}

View File

@ -1,42 +1,54 @@
{% set current_lang = config.default_language %}
{% if page %}
{% set current_lang = page.lang %}
{% elif section %}
{%- set current_lang = section.lang %}
{% endif %}
{% if config.extra.nav.links %}
<header id="site-nav">
<nav>
<a href="#main" id="main-content" tabindex="0">Skip to main content</a>
<a href="#main" id="main-content" tabindex="0">{{ trans(key="skip_to_content", default="Skip to main content", lang=lang) }}</a>
<ul>
<li id="home">
<a href="{{ get_url(path='/') | safe }}"
{% if current_url | default(value='/') | trim_end_matches(pat='/') | safe == get_url(path='/') | safe %}
<a href="{{ get_url(path='/', lang=lang) }}"
{% if current_url | default(value='/') | trim_end_matches(pat='/') == get_url(path='/') %}
class="active"
{% endif %}>
{{ config.title }}
</a>
</li>
{% for link in config.extra.nav.links %}
{% if current_lang == config.default_language %}
{% set title = link.name %}
{% else %}
{% set language_key = 'name_' ~ current_lang %}
{% set title = link[language_key] %}
{% endif %}
{%- if link.url is matching('https?://') %}
<li class="link">
<a href="{{ link.url | safe }}"
{% if current_url | default(value='/') | safe == link.url | safe %}
<a href="{{ link.url }}"
{% if current_url | default(value='/') == link.url %}
class="active"
{% endif %}>
{{ link.name }}
{{ title }}
</a>
</li>
{%- else %}
<li class="link">
<a href="{{ get_url(path=link.url | safe )}}"
{% if current_url | default(value='/') | safe == get_url(path=link.url) | safe %}
<a href="{{ get_url(path=link.url, lang=lang)}}"
{% if current_url | default(value='/') == get_url(path=link.url, lang=lang) %}
class="active"
{% endif %}>
{{ link.name }}
{{ title }}
</a>
</li>
{%- endif %}
{% endfor %}
{% if config.extra.nav.show_feed %}
{% if config.generate_feed and config.extra.nav.show_feed %}
<li id="feed">
<a href="{{ get_url(path=config.feed_filename) | safe }}">
<a href="{{ get_url(path=config.feed_filename) }}">
<i class="icon"></i>
<span>Feed</span>
<span>{{ trans(key="feed", default="Feed", lang=lang) }}</span>
</a>
</li>
{% endif %}

View File

@ -0,0 +1,7 @@
{%- if page.title -%}
{{- page.title }} - {{ config.title -}}
{%- elif section.title -%}
{{- section.title }} - {{ config.title -}}
{%- else -%}
{{- config.title -}}
{%- endif -%}

View File

@ -1,13 +1,13 @@
{% extends "base.html" %}
{% block content %}
<h1>Tags</h1>
<small> {{ terms | length }} tags in total </small>
<h1>{{ trans(key="tags", default="Tags", lang=lang) }}</h1>
<small>{{ terms | length }} {{ trans(key="tags_in_total", default="tags in total", lang=lang) }}</small>
<br />
<small>
<ul class="tags">
{% for tag in terms %}
<li><a class="tag" href="{{ get_taxonomy_url(kind='tags', name=tag.name) }}">{{ tag.name }}</a></li>
<li><a class="tag" href="{{ get_taxonomy_url(kind='tags', name=tag.name, lang=lang) }}">{{ tag.name }}</a></li>
{% endfor %}
</ul>
</small>

View File

@ -1,11 +1,11 @@
{% extends "base.html" %}
{% block content %}
<h1>Posts with tag “{{ term.name }}”</h1>
<h1>{{ trans(key="posts_with_tag", default="Posts with tag", lang=lang) }} “{{ term.name }}”</h1>
<small>
<a class="link-page" href="{{ get_url(path='tags') }}">See all tags</a>
<a class="link-page" href="{{ get_url(path='tags', lang=lang) }}">{{ trans(key="see_all_tags", default="See all tags", lang=lang) }}</a>
<br />
{{ term.pages | length }} posts in total
{{ term.pages | length }} {{ trans(key="posts_in_total", default="posts in total", lang=lang) }}
</small>
<article>
{% for page in term.pages %}
@ -20,7 +20,7 @@
<span></span>
<ul class="tags">
{%-for item in taxon %}
<li><a class="tag" href="{{ get_taxonomy_url(kind=name, name=item) }}">{{ item }}</a></li>
<li><a class="tag" href="{{ get_taxonomy_url(kind=name, name=item, lang=lang) }}">{{ item }}</a></li>
{%- endfor %}
</ul>
{%- endfor %}