Repository navigation
Fix news media rendering and archive image loading #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) %} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 It is still better than master, where the images had no
A smaller, separate point on the same line: a non-string value is rendered as is. I built a post with 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" -%} | ||
|
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 -%} | ||
|
vng marked this conversation as resolved.
Resolved
|
||
| {%- endfor -%} | ||
| {%- endcomponent news_media %} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 The archive entry still differs from the listing entry for the same post: it has no post title, no Con: the archive would gain a title and the taxonomy Generated by Claude Code |
||
| </div> | ||
| {% endfor %} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.
Generated by Claude Code