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

@ -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 -%}