summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-03-30 16:16:03 +0800
committereltrac <hi@eltr.ac>2026-03-30 16:16:03 +0800
commit78cec130a4260605cc748e1c36171a45cf64a3b5 (patch)
tree74b7495eb38a245ebe09f9963f053eac7592b826
parent4685f8f1c878d8d38990ea5282c168ed5227655b (diff)
refactor: fetch webmention data from source on every build
-rw-r--r--config/_default/params.toml3
-rw-r--r--layouts/_partials/posts/action-menu.html106
2 files changed, 58 insertions, 51 deletions
diff --git a/config/_default/params.toml b/config/_default/params.toml
index 33907fb0..652fdf81 100644
--- a/config/_default/params.toml
+++ b/config/_default/params.toml
@@ -4,6 +4,9 @@ email = "hi@eltr.ac"
mainSections = ["article", "weekly", "fiction", "library"]
favicon = "/favicon.png"
+[webmention]
+src = "https://wm.geedea.pro/api/mentions/www.geedea.pro"
+
[author]
email = "hi@eltr.ac"
name = "Eltrac"
diff --git a/layouts/_partials/posts/action-menu.html b/layouts/_partials/posts/action-menu.html
index e0144816..f8234272 100644
--- a/layouts/_partials/posts/action-menu.html
+++ b/layouts/_partials/posts/action-menu.html
@@ -1,66 +1,70 @@
+{{ $page := . }}
{{ $currentPagePath := .RelPermalink }}
-{{ $webmentions := slice }}
+{{ $webmentions_url := .Site.Params.webmention.src }}
-{{ range hugo.Data.webmentions }}
- {{ $urlObj := urls.Parse .webmention.target }}
- {{ $targetPath := $urlObj.Path }}
+{{ with try (resources.GetRemote $webmentions_url) }}
+ {{ with .Err }}
+ {{ errorf "%s" . }}
- {{ if or (strings.Contains $targetPath $currentPagePath)
- (strings.Contains $targetPath ($currentPagePath | urlquery)) }}
- {{ $webmentions = $webmentions | append . }}
- {{ end }}
-{{ end }}
+ {{ else with .Value }}
+ {{ $webmentions := slice }}
+ {{ $data := . | transform.Unmarshal }}
+ {{ range $data }}
+ {{ $urlObj := urls.Parse .webmention.target }}
+ {{ $targetPath := $urlObj.Path }}
-<!--
- some pages were moved, merge their webmention with old Data
--->
-{{ $other_webmentions := where hugo.Data.webmentions "webmention.target" (printf "/posts%s" .RelPermalink ) }}
-{{ if $other_webmentions }}
- {{ $webmentions = $webmentions | union $other_webmentions }}
-{{ end }}
+ {{ if or (strings.Contains $targetPath $currentPagePath)
+ (strings.Contains $targetPath ($currentPagePath | urlquery)) }}
+ {{ $webmentions = $webmentions | append . }}
+ {{ end }}
+ {{ end }}
-{{ $likes := slice }}
-{{ $replies := slice }}
-{{ $reposts := slice }}
-{{ $mentions := slice }}
+ {{ $likes := slice }}
+ {{ $replies := slice }}
+ {{ $reposts := slice }}
+ {{ $mentions := slice }}
-{{ range $webmentions }}
- {{ $props := index . "microformats" "properties" }}
- {{ $type := index . "microformats" "type" 0 }}
+ {{ range $webmentions }}
+ {{ $props := index . "microformats" "properties" }}
+ {{ $type := index . "microformats" "type" 0 }}
- {{ if eq $type "h-entry" }}
- {{ if index $props "like-of" }}
- {{ $likes = $likes | append . }}
+ {{ if eq $type "h-entry" }}
+ {{ if index $props "like-of" }}
+ {{ $likes = $likes | append . }}
- {{ else if index $props "repost-of" }}
- {{ $reposts = $mentions | append . }}
+ {{ else if index $props "repost-of" }}
+ {{ $reposts = $mentions | append . }}
- {{ else }}
- {{ $replies = $replies | append . }}
+ {{ else }}
+ {{ $replies = $replies | append . }}
- {{ end }}
- {{ else }}
- {{ $mentions = $mentions | append . }}
- {{ end }}
+ {{ end }}
+ {{ else }}
+ {{ $mentions = $mentions | append . }}
+ {{ end }}
-{{ end }}
+ {{ end }}
-{{ partial "posts/action-area" . }}
-<details class="my-4 mb-5 no-mark">
- <summary class="cursor-pointer flex">
- {{ partial "posts/webmention-summary" (dict
- "likes" $likes
- "page" .
- "othercount" (add (len $replies) (len $mentions))
- ) }}
- </summary>
- <div id="webmention-details">
- {{ partial "posts/webmention-replies" $replies }}
- {{ partial "posts/webmention-mentions" $mentions }}
- </div>
+ {{ partial "posts/action-area" $page }}
+ <details class="my-4 mb-5 no-mark">
+ <summary class="cursor-pointer flex">
+ {{ partial "posts/webmention-summary" (dict
+ "likes" $likes
+ "page" $page
+ "othercount" (add (len $replies) (len $mentions))
+ ) }}
+ </summary>
+ <div id="webmention-details">
+ {{ partial "posts/webmention-replies" $replies }}
+ {{ partial "posts/webmention-mentions" $mentions }}
+ </div>
- <!-- kept for legacy pages -->
- {{ partial "posts/comment" . }}
-</details>
+ <!-- kept for legacy pages -->
+ {{ partial "posts/comment" $page }}
+ </details>
+ {{ else }}
+ <p>Unable to fetch webmentions. Please contact webmaster.</p>
+ {{ end }}
+{{ end }}