Merge branch 'rewrite-figures'

Fixes #87
Fixes #61
This commit is contained in:
2025-07-27 03:55:06 -05:00
11 changed files with 66 additions and 96 deletions

View File

@@ -198,14 +198,14 @@ video {
max-width: 100%;
}
.post-media > figure.border img,
.post-media > figure.border video {
.post-media > figure img,
.post-media > figure video {
padding: 5px;
border: 7px solid var(--figure-border);
}
figure.border img,
figure.border video {
figure img,
figure video {
padding: 5px;
border: 2px solid var(--figure-border);
}

View File

@@ -7,6 +7,8 @@ table_of_contents:
browser_no_video_support:
other: "Your browser does not support video."
browser_no_video_support_link:
other: "Click here to download it instead."
latest_posts:
other: "Latest Posts"

View File

@@ -0,0 +1,23 @@
{{ if eq .ResourceType "image" }}
{{/* TODO: figure out whether loading="lazy" should be set because MDN
* claims that images won't work with JS disabled since it would
* make tracking possible, but my experience says otherwise
*/}}
<img src="{{ .Permalink }}" {{ with .Params.alt }}alt="{{ . }}"{{ end }} />
{{ else if eq .ResourceType "video" }}
<video controls preload="metadata">
{{ with .Params.alt }}
{{ warnf "video does not support alt text, '%s'" . }}
{{ end }}
<source src="{{ .Permalink }}" />
{{ i18n "browser_no_video_support" }}
<a href="{{ .Permalink }}" target="_blank" rel="noopener">
{{ i18n "browser_no_video_support_link" }}
</a>
</video>
{{ else }}
{{/* TODO: could consider implementing more types, listed at:
* https://www.iana.org/assignments/media-types/media-types.xhtml
*/}}
{{ errorf "Handling %q resource not supported" .ResourceType }}
{{ end }}

View File

@@ -0,0 +1,10 @@
{{ with .Resources.Get "feature" }}
<div class="post-media">
<figure>
{{ partial "embed-resource.html" . }}
{{ with .Title }}
<figcaption>{{ . | markdownify }}</figcaption>
{{ end }}
</figure>
</div>
{{ end }}

View File

@@ -1,27 +0,0 @@
{{ $hidecaption := index . "hidecaption" }}
{{ if index . "noborder" }}
<figure>
{{ else }}
<figure class="border">
{{ end }}
{{ with index . "src" }}
{{ if eq .MediaType.MainType "image" }}
<img src="{{ .Permalink }}" alt="{{ .Title }}" loading="lazy" />
{{ else if eq .MediaType.MainType "video" }}
<video controls preload="metadata">
<source src="{{ .Permalink }}" alt="{{ .Title }}">
{{ i18n "browser_no_video_support" }}
</video>
{{ end }}
{{ if not $hidecaption }}
{{ with .Title }}
<figcaption>
{{ . | markdownify }}
</figcaption>
{{ end }}
{{ end }}
{{ end }}
</figure>

View File

@@ -1,28 +0,0 @@
{{ $hidecaption := index . "hidecaption" }}
{{ $type := index . "type" }}
{{ $src := index . "src" }}
{{ $alt := index . "alt" }}
{{ if index . "border" }}
<figure class="border">
{{ else }}
<figure>
{{ end }}
{{ if eq $type "image" }}
<img src="{{ $src }}" alt="{{ $alt }}" loading="lazy" />
{{ else if eq $type "video" }}
<video controls preload="metadata">
<source src="{{ $src }}" alt="{{ $alt }}">
{{ i18n "browser_no_video_support" }}
</video>
{{ end }}
{{ if not $hidecaption }}
{{ with $alt }}
<figcaption>
{{ . | markdownify }}
</figcaption>
{{ end }}
{{ end }}
</figure>

View File

@@ -1,15 +1,17 @@
{{ $resource := .Page.Resources.GetMatch (.Get "src") }}
{{ $noborder := false }}
{{ if .Get "noborder" }}
{{ $noborder = true }}
<figure>
{{ $resource_title := "" }}
{{ with .Get "src" }}
{{ with $.Page.Resources.Get . }}
{{ $resource_title = .Title }}
{{ partial "embed-resource.html" . }}
{{ else }}
{{ errorf "resource %q not found" . }}
{{ end }}
{{ else }}
{{ .Inner }}
{{ end }}
{{ $hidecaption := false }}
{{ if .Get "hidecaption" }}
{{ $hidecaption = true }}
{{ with or (.Get "caption") (.Get 0) $resource_title }}
<figcaption>{{ . | markdownify }}</figcaption>
{{ end }}
<p>
{{ partial "figure.html" (dict "src" $resource "noborder" $noborder "hidecaption" $hidecaption) }}
</p>
</figure>

View File

@@ -1,13 +0,0 @@
{{ $border := false }}
{{ if .Get "border" }}
{{ $border = true }}
{{ end }}
{{ $hidecaption := false }}
{{ if .Get "hidecaption" }}
{{ $hidecaption = true }}
{{ end }}
<p>
{{ partial "remote_figure.html" (dict "src" (.Get "src") "border" $border "hidecaption" $hidecaption "type" (.Get "type") "alt" (.Get "alt")) }}
</p>

View File

@@ -0,0 +1,9 @@
{{ with .Get 0 }}
{{ with $.Page.Resources.Get . }}
{{ partial "embed-resource.html" . }}
{{ else }}
{{ errorf "resource %q not found" . }}
{{ end }}
{{ else }}
{{ errorf "resource name not provided as first parameter" }}
{{ end }}

View File

@@ -22,11 +22,7 @@
</div>
{{ end }}
{{ with .Resources.GetMatch "feature" }}
<div class="post-media">
{{ partial "figure.html" (dict "src" .) }}
</div>
{{ end }}
{{ partial "feature-figure.html" . }}
<article class="post-content">
{{ .Content }}

View File

@@ -6,11 +6,7 @@
{{ partial "page-metadata/post-short.html" . }}
{{ with .Resources.GetMatch "feature" }}
<div class="post-media">
{{ partial "figure.html" (dict "src" .) }}
</div>
{{ end }}
{{ partial "feature-figure.html" . }}
<div class="page-description">
{{ partial "description-or-summary.html" . }}