Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ In content Markdown, call components with `{{ <name arguments /> }}` syntax:

- `{{ <badges lang /> }}` → App store download badges
- `{{ <screenshot src='/images/screenshots/hiking.jpg' alt='Hiking' /> }}` → Responsive image
- Component templates remain in `templates/shortcodes/` as `.html` or `.md` files and declare their interface with `{% component ... %}`
- Content component templates live in `templates/shortcodes/` as `.html` or `.md` files and declare their interface with `{% component ... %}`. Shared template components also live directly in `templates/`: `_news_media.html` renders news galleries and `_news_preview.html` resolves parent-folder covers.

### Resource References in Templates

Expand Down Expand Up @@ -248,7 +248,7 @@ python3 tools/translate_md.py content/news/2026-08-04/630/index.md --all
python3 tools/translate_md.py post.md --langs ru --dry-run # cost, no API call
```

It translates `title:` and `description:` **and nothing else in the frontmatter** — `extra:` is copied verbatim, so a page that keeps user-visible text there (`extra.menu_title`, the donation form's `extra.form.*` labels) needs those translated by hand. `translate_check.py` warns when one is still identical to English. It leaves `date:`/`slug:`/`taxonomies:` verbatim, rewrites `@/…/index.md` links to the translated page when that page exists, applies the glossary below, and runs the tidy-up passes (native quotes, brand unquoting, ellipsis, link-label hygiene, register where DeepL supports it). **Output is a draft**: wording and the expected target-language register still need the proofreading pass.
It translates `title:` and `description:` **and nothing else in the frontmatter** — `extra:` is copied verbatim, so a page that keeps user-visible text there (`extra.menu_title`, the donation form's `extra.form.*` labels, news image descriptions in `extra.media_alt`) needs those translated by hand. `translate_check.py` warns when one is still identical to English, and when a translation omits an English `extra.media_alt` entry (including an empty value for a decorative image). It leaves `date:`/`slug:`/`taxonomies:` verbatim, rewrites `@/…/index.md` links to the translated page when that page exists, applies the glossary below, and runs the tidy-up passes (native quotes, brand unquoting, ellipsis, link-label hygiene, register where DeepL supports it). **Output is a draft**: wording and the expected target-language register still need the proofreading pass.

Complete code blocks, comments and Tera expressions are protected before
segmentation, and formatting that crosses a soft line break stays in one valid
Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ taxonomies:
```

JPEG, PNG and WebP images stored alongside a news post are rendered automatically.
The article, news listing and date archive share one media renderer. Filenames
are sorted and extensions are case-insensitive. MP4 files render as videos;
MP3 files can be embedded in the text with the `audio` component. Other file
types stop the build. Images reserve their dimensions and use async decoding;
listing and archive images load lazily. Articles keep their first image eager.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs (fix here, wording only): describe the behavior, not its history.

"Keep" only makes sense to someone who knows the earlier article template.

Suggested change
listing and archive images load lazily. Articles keep their first image eager.
listing and archive images load lazily. Articles load their first image eagerly.

Generated by Claude Code

Listing and archive videos preload metadata so their previews and dimensions
are available before playback.

Add specific image descriptions in each translation's frontmatter:

```yaml
extra:
media_alt:
"01-map.webp": "Mountain trails and contour lines around the summit"
"02-decoration.png": ""
```

Keys must match image filenames exactly or the build stops. An image without
a `media_alt` entry uses the localized article title; use an empty description
only for decorative or redundant images. Translate `extra.media_alt` manually,
because `translate_md.py` copies `extra` unchanged. `translate_check.py` warns
when an entry from the English source is missing (including an empty entry
for a decorative image), or a description is still identical to English.

Social previews use this order:

1. An explicit `extra.preview_image` (a colocated filename or site-root path).
Expand All @@ -58,7 +82,9 @@ stays out of the article gallery and Telegram album. Explicit and automatic
parent previews are included in the image sitemap. Missing explicit local
previews stop the build instead of publishing broken image URLs.

Telegram media discovery also recognizes `.webp` files.
Telegram media discovery also recognizes `.webp` files. Standalone Telegram
folders can include `.mov` and `.m4a`; news folders must use the website's
supported formats listed above.
For shared images in `static/`, the `screenshot` component accepts WebP paths and
reads their dimensions just as it does for JPEG and PNG.

Expand Down
40 changes: 40 additions & 0 deletions templates/_news_media.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% component news_has_landscape(resource) -%}
{%- for media in resource.assets -%}
{%- set extension = media | split(pat=".") | last | lower -%}
{%- if extension in ["jpg", "jpeg", "png", "webp"] -%}
{%- set meta = get_image_metadata(path=media) -%}
{%- if meta.width > meta.height -%}true{%- break -%}{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endcomponent news_has_landscape %}

{% component news_media(resource, eager_first_image=false, autoplay=false) -%}
{%- set alts = resource.extra | get(key="media_alt", default={}) -%}
{%- set_global first_image = true -%}
{%- set_global image_filenames = [] -%}
{%- for media in resource.assets | sort -%}
{%- set filename = media | split(pat="/") | last -%}
{%- set extension = filename | split(pat=".") | last | lower -%}
{%- set url = resource.path ~ (filename | urlencode) -%}
{%- if extension == "mp4" %}
<video class="news_video" controls{% if autoplay %} autoplay muted{% else %} preload="metadata"{% endif %}>
<source src="{{ url }}" type="video/mp4">
</video>
{%- elif extension in ["jpg", "jpeg", "png", "webp"] -%}
{%- set meta = get_image_metadata(path=media) -%}
{%- set_global image_filenames = [...image_filenames, filename] -%}
{%- set alt = alts | get(key=filename, default=resource.title) %}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessibility trade-off (optional, decide here or separately): the title fallback repeats the heading for every image.

No post has media_alt yet, so in the built /news/ all 198 gallery images carry their post title as alt. One post repeats a 190-character title 9 times, directly after the <h1> with the same text. A screen reader announces all of them. Accessibility checkers such as WAVE report this as redundant alternative text.

It is still better than master, where the images had no alt at all, so this does not block the change. Options:

  • Keep it. Every image is announced, and the repetition goes away as posts gain media_alt.
  • Fall back to alt="" where the title is already next to the gallery (article and listing), and keep the title in the date archive, which has no heading per post. Con: an undescribed screenshot is then hidden from screen readers in those two views, and the component needs one more argument.

A smaller, separate point on the same line: a non-string value is rendered as is. I built a post with "b.png": 5 and got alt="5"; translate_check.py only reads string values, so it does not report it either. A bare "a.png": already stops the build with a frontmatter error.


Generated by Claude Code

<img class="news_image{% if meta.width > meta.height %}_landscape{% endif %}" src="{{ url }}" width="{{ meta.width }}" height="{{ meta.height }}" alt="{{ alt }}" loading="{% if eager_first_image and first_image %}eager{% else %}lazy{% endif %}" decoding="async" />
{%- set_global first_image = false -%}
{#- The audio component embeds MP3s in the article text. Any other type
would be missing from the site without a signal, so it stops the build. -#}
{%- elif extension != "mp3" -%}
Comment thread
vng marked this conversation as resolved.
Resolved
{{- throw(message="Unsupported news asset '" ~ media ~ "'") -}}
{%- endif -%}
{%- endfor -%}
{%- for filename, _description in alts -%}
{%- if filename not in image_filenames -%}
{{- throw(message="media_alt key '" ~ filename ~ "' matches no image asset of " ~ resource.relative_path) -}}
{%- endif -%}
Comment thread
vng marked this conversation as resolved.
Resolved
{%- endfor -%}
{%- endcomponent news_media %}
6 changes: 3 additions & 3 deletions templates/news/date_section.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ <h1>{{ resource.title }}</h1>
{% if page.content %}
<div class="news_content">{{ page.content | safe }}</div>
{% endif %}
{% for photo in page.assets %}
<img class="news_image" src="{{ page.path | safe }}{{ photo | split(pat='/') | last }}" />
{% endfor %}
<span class="news_images">
{{ <news_media resource={page} /> }}
</span>
Comment on lines +15 to +17

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative (mostly pre-existing, optional separate PR): share the whole post entry, not only its media.

This change is a clear improvement: on master /news/2026-11-11/ scrolls horizontally to 2334px at a 1280px viewport, and here it fits.

The archive entry still differs from the listing entry for the same post: it has no post title, no dir="auto" for untranslated posts, and no wide-image layout. Moving the listing's per-post block (date, title, content, media) into one news_entry component used by both list.html and date_section.html would remove those differences and the duplicated translation lookup.

Con: the archive would gain a title and the taxonomy section wrapper, which is a visible change that deserves its own review.


Generated by Claude Code

</div>
{% endfor %}

Expand Down
30 changes: 4 additions & 26 deletions templates/news/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,17 @@ <h1>{{ resource.title }}</h1>
<div class="news_date">&nbsp;<a href="{{ page.path | safe }}">{{ page.date | date(format='%B %e, %Y') }}</a>&nbsp;</div>
<h1>{{ page.title | safe }}</h1>
{# Display wide images below the text instead of to the right. #}
{% set_global noflex = '' %}
{% for photo in page.assets %}
{% if photo is not matching(pat="\\.mp[34]$") %}
{% set meta = get_image_metadata(path=photo) %}
{# TODO: How to get dimensions of video? #}
{% if meta.width > meta.height %}
{% set_global noflex = '_noflex' %}
{% break %}
{% endif %}
{% endif %}
{% endfor %}
<div class="news_content_image{{ noflex }}">
{% set has_landscape = <news_has_landscape resource={page} /> %}
<div class="news_content_image{% if has_landscape %}_noflex{% endif %}">
Comment thread
biodranik marked this conversation as resolved.
Resolved
{% if page.content %}
<div class="news_content">{{ page.content | safe }}</div>
{% endif %}

<span class="news_images">
{% for media in page.assets | sort %}
{% if media is matching(pat="\\.mp3$") %}
{% elif media is matching(pat="\\.mp4$") %}
<video class="news_video" controls>
<source src="{{ page.path | safe }}{{ media | split(pat='/') | last }}" type="video/mp4">
</video>
{% else %} {# It's images #}
{% set meta = get_image_metadata(path=media) %}
<img class="news_image{% if meta.width > meta.height %}_landscape{% endif %}" src="{{ page.path | safe }}{{ media | split(pat='/') | last }}" />
{% endif %}
{% endfor %}
{{ <news_media resource={page} /> }}
</span>

</section>

</div>
</section>
{% endfor %}
{% endfor %}

Expand Down
12 changes: 1 addition & 11 deletions templates/news/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ <h1>{{ resource.title }}</h1>
{{ resource.content | safe }}
</div>

{% for media in resource.assets | sort %}
{% if media is ending_with(pat=".mp4") %}
<video class="news_video" controls autoplay muted>
<source src="{{ resource_path | safe }}{{ media | split(pat='/') | last }}" type="video/mp4">
</video>
{% elif media is ending_with(pat=".mp3") %}
{% else %} {# Match remaining file types as images #}
{% set meta = get_image_metadata(path=media) %}
<img class="news_image{% if meta.width > meta.height %}_landscape{% endif %}" src="{{ resource_path | safe }}{{ media | split(pat='/') | last }}" width="{{ meta.width }}" height="{{ meta.height }}" loading="{% if loop.first %}eager{% else %}lazy{% endif %}" decoding="async" />
{% endif %}
{% endfor %}
{{ <news_media resource eager_first_image={true} autoplay={true} /> }}

{% set news_root = get_taxonomy(kind='news', lang=lang) %}
<div class="back_to_news">
Expand Down
42 changes: 41 additions & 1 deletion tmp/test_tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
validate_media_set,
visible_text,
)
from translate_check import ERROR, check_translation, emphasis_faults # noqa: E402
from translate_check import ERROR, WARN, check_translation, emphasis_faults # noqa: E402
from translate_md import ( # noqa: E402
_segments, localize_zola_links, register_ok, tidy, translate_post, translate_text,
)
Expand Down Expand Up @@ -109,6 +109,46 @@ def test_register_is_checked_in_reader_visible_frontmatter(self):
for p in check_translation(
source, translated.replace("Ihre", "Deine"), "de")))

def test_missing_image_descriptions_are_reported(self):
source = ('---\ntitle: News\nextra:\n menu_title: News\n media_alt:\n'
' "map.webp": Mountain trails\n "decoration.png": ""\n'
'---\n\nOrganic Maps.\n')
cases = {
"no extra": ('---\ntitle: Neuigkeiten\n---\n\nOrganic Maps.\n',
["map.webp", "decoration.png"]),
"no media_alt": ('---\ntitle: Neuigkeiten\nextra:\n menu_title: Neuigkeiten\n'
'---\n\nOrganic Maps.\n', ["map.webp", "decoration.png"]),
"empty media_alt": ('---\ntitle: Neuigkeiten\nextra:\n media_alt: {}\n'
'---\n\nOrganic Maps.\n', ["map.webp", "decoration.png"]),
"no frontmatter": ('Organic Maps.\n', ["map.webp", "decoration.png"]),
"missing decorative entry": ('---\ntitle: Neuigkeiten\nextra:\n media_alt:\n'
' "map.webp": Bergpfade\n---\n\nOrganic Maps.\n',
["decoration.png"]),
"missing descriptive entry": ('---\ntitle: Neuigkeiten\nextra:\n media_alt:\n'
' "decoration.png": ""\n---\n\nOrganic Maps.\n',
["map.webp"]),
}
for case, (translated, missing) in cases.items():
with self.subTest(case=case):
problems = check_translation(source, translated, "de")
warnings = [p for p in problems if p.code == "missing-media-alt"]
self.assertCountEqual([p.message for p in warnings],
[f"'extra.media_alt.{name}' is missing from the translation"
for name in missing])
self.assertTrue(all(p.level == WARN for p in warnings))
self.assertFalse(any(p.level == ERROR for p in problems), problems)

def test_complete_image_descriptions_preserve_empty_values_and_source_keeps(self):
source = ('---\ntitle: News\nextra:\n media_alt:\n'
' "map.webp": Panorama\n "decoration.png": ""\n'
'---\n\nOrganic Maps.\n')
translated = source.replace("title: News", "title: Neuigkeiten")
self.assertEqual(check_translation(source, translated.replace("Panorama", "Berglandschaft"), "de"), [])
declared = translated.replace(' media_alt:', ' translation_keeps_source: ["extra.media_alt.map.webp"]\n media_alt:')
self.assertEqual(check_translation(source, declared, "de"), [])
self.assertEqual([p.code for p in check_translation(source, translated, "de")],
["untranslated-frontmatter"])

def test_sentence_initial_occitan_address_is_detected(self):
self.assertFalse(register_ok("Vòstre pagament es estat anullat.", "oc")[0])
self.assertTrue(register_ok("Ton pagament es estat anullat.", "oc")[0])
Expand Down
Binary file added tools/fixtures/portrait-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading