summaryrefslogtreecommitdiff
path: root/layouts/_partials
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-03-14 17:36:52 +0800
committereltrac <hi@eltr.ac>2026-03-14 17:36:52 +0800
commit3cfe78392bb001d1dd81a184e8e083fb90eec656 (patch)
tree70519878ae578c7c5e7c5aedefd745b39e3bc821 /layouts/_partials
parent766a3c5ffeb83911c296e562bd1c95f90a803b7f (diff)
refactor(webmention): use new data format
Diffstat (limited to 'layouts/_partials')
-rw-r--r--layouts/_partials/posts/action-menu.html38
-rw-r--r--layouts/_partials/posts/webmention-mentions.html15
-rw-r--r--layouts/_partials/posts/webmention-replies.html23
-rw-r--r--layouts/_partials/posts/webmention-summary.html6
4 files changed, 59 insertions, 23 deletions
diff --git a/layouts/_partials/posts/action-menu.html b/layouts/_partials/posts/action-menu.html
index d3544c1f..fdb45596 100644
--- a/layouts/_partials/posts/action-menu.html
+++ b/layouts/_partials/posts/action-menu.html
@@ -1,27 +1,49 @@
-{{ $webmentions := index .Site.Data.webmentions .RelPermalink }}
+{{ $currentPagePath := .RelPermalink }}
+{{ $webmentions := slice }}
+
+{{ range .Site.Data.webmentions }}
+ {{/* 1. 解析数据中的绝对 URL */}}
+ {{ $urlObj := urls.Parse .webmention.target }}
+
+ {{/* 2. 获取其路径部分(例如 /posts/hello-world/) */}}
+ {{ $targetPath := $urlObj.Path }}
+
+ {{/* 3. 对比:考虑原始路径和编码后的路径 */}}
+ {{ if or (eq $targetPath $currentPagePath) (eq $targetPath ($currentPagePath | urlquery)) }}
+ {{ $webmentions = $webmentions | append . }}
+ {{ end }}
+{{ end }}
+
<!--
some pages were moved, merge their webmention with old Data
-->
-{{ $other_webmentions := index .Site.Data.webmentions (printf "/posts%s" .RelPermalink ) }}
+{{ $other_webmentions := where .Site.Data.webmentions "webmention.target" (printf "/posts%s" .RelPermalink ) }}
{{ if $other_webmentions }}
{{ $webmentions = $webmentions | union $other_webmentions }}
{{ end }}
{{ $likes := slice }}
{{ $replies := slice }}
+{{ $reposts := slice }}
{{ $mentions := slice }}
-{{ with $webmentions }}
-{{ range . }}
- {{ if eq .type "like-of" }}
+
+{{ range $webmentions }}
+ {{ $props := index . "microformats" "properties" }}
+
+ {{ if index $props "like-of" }}
{{ $likes = $likes | append . }}
- {{ else if eq .type "in-reply-to" }}
+
+ {{ else if index $props "in-reply-to" }}
{{ $replies = $replies | append . }}
- {{ else if eq .type "mention-of" }}
+
+ {{ else if index $props "repost-of" }}
+ {{ $reposts = $mentions | append . }}
+
+ {{ else }}
{{ $mentions = $mentions | append . }}
{{ end }}
{{ end }}
-{{ end }}
{{ partial "posts/action-area" . }}
<details class="my-4 mb-5 no-mark">
diff --git a/layouts/_partials/posts/webmention-mentions.html b/layouts/_partials/posts/webmention-mentions.html
index dca0e8db..ecfd990a 100644
--- a/layouts/_partials/posts/webmention-mentions.html
+++ b/layouts/_partials/posts/webmention-mentions.html
@@ -1,9 +1,16 @@
{{ with . }}
-<section class="markdown-body">
-<h3>{{ T "webmention.mentionsHeading" . }}</h3>
-<ul class="">
+<section class="my-4">
+<ul class="list-none p-0 m-0">
{{ range . }}
- <li><a href="{{ .url }}" target="_blank">{{ .url }}</a></li>
+ {{ if index . "microformats" }}
+ {{ $mf := index . "microformats" "properties" }}
+ {{ $author := index (index (index $mf "author") 0) "properties" }}
+ <li class="flex gap-2"><img src="{{ index $author.photo 0 }}" class="h-5 w-5 rd-full w-auto inline m-0">
+ <a href="{{ index $author.url 0 }}">{{ index $author.name 0 }}</a>
+ <a href="{{ .webmention.source }}">{{ T "webmention.mentionedThisPost" . }}</a></li>
+ {{ else }}
+ <li><a href="{{ .webmention.source }}" target="_blank">{{ .webmention.source }}</a></li>
+ {{ end }}
{{ end }}
</ul>
</section>
diff --git a/layouts/_partials/posts/webmention-replies.html b/layouts/_partials/posts/webmention-replies.html
index a762b29b..11beef06 100644
--- a/layouts/_partials/posts/webmention-replies.html
+++ b/layouts/_partials/posts/webmention-replies.html
@@ -1,31 +1,36 @@
{{ with . }}
<section class="flex flex-col gap-4 bg-[var(--background-color)]">
-{{ range sort . "received" }}
+{{ range . }}
+ {{ $reply := index . "microformats" "properties" }}
+ {{ $author := index (index $reply "author") 0 }}
+ {{ $author = index $author "properties" }}
+
<div class="b-1 b-solid b-neutral-200 dark:b-neutral-700 rd p-4 relative">
<header class="flex justify-between items-start">
<div class="flex items-center gap-3">
- <img src="{{ .author.photo }}" alt="Profile Picture"
+ <img src="{{ index $author.photo 0 }}" alt="Profile Picture"
class="h-8 w-8 rd-full" loading="lazy" />
<div class="text-secondary">
<p class="font-bold m-0">
- <a href="{{ or .author.url .url }}">
- {{ replaceRE ":.*?:" "" .author.name }}
+ <a href="{{ or (index $author.url 0)
+ (index $reply.url 0) }}">
+ {{ replaceRE ":.*?:" "" (index $author.name 0) }}
</a>
</p>
- {{ $t := time.AsTime .received }}
- <p class="m-0"><time>{{ time.Format "2006-1-2" $t}}</time></p>
+ {{ $t := time.AsTime (index $reply.published 0) }}
+ <p class="m-0"><time>{{ time.Format "2006-1-2 15:04" $t}}</time></p>
</div>
</div>
<div class="flex items-start">
- <a href="{{ .source }}" target="_blank"
+ <a href="{{ .webmention.source }}" target="_blank"
title="{{ T "viewExternalSource" }}"
data-tooltip>↗</a>
</div>
</header>
- <div class="markdown-body leading-relaxed px-2">{{ .content.html | safeHTML }}</div>
+ <div class="markdown-body leading-relaxed px-2">{{ index (index $reply.content 0) "html" | safeHTML }}</div>
- {{ if strings.Contains .source "https://brid.gy" }}
+ {{ if strings.Contains .webmention.source "https://brid.gy" }}
<p class="text-xs text-right text-secondary">通过 <a href="https://brid.gy/" target="_blank">Bridgy</a> 发送自联邦宇宙</p>
{{ end }}
</div>
diff --git a/layouts/_partials/posts/webmention-summary.html b/layouts/_partials/posts/webmention-summary.html
index b7c19451..e1b477de 100644
--- a/layouts/_partials/posts/webmention-summary.html
+++ b/layouts/_partials/posts/webmention-summary.html
@@ -15,10 +15,12 @@
<!-- Likes -->
{{ range $likes }}
- <a href="{{ .author.url }}" target="_blank" title="{{ .author.name }}" class="box-border hover:no-underline inline-block h-5 w-5 float-left -ml-1">
+ {{ $authors := index . "microformats" "properties" "author" }}
+ {{ $author := index (index $authors 0) "properties" }}
+ <a href="{{ index $author.url 0 }}" target="_blank" title="{{ index $author.name 0 }}" class="box-border hover:no-underline inline-block h-5 w-5 float-left -ml-1">
{{ $value := math.Floor (mul math.Rand 80) }}
{{ $rotate := cond (lt $value 40) (sub 10 $value) (sub $value 30) }}
- <img src="{{ .author.photo }}" alt="Profile Picture"
+ <img src="{{ index $author.photo 0 }}" alt="Profile Picture"
loading="lazy"
class="h-5 w-5 rd-full transition-transform {{ if lt $rotate 0 }}group-hover:-rotate-{{ mul -1 $rotate }}{{ else }}group-hover:rotate-{{ $rotate }}{{ end }} hover:scale-150" />
</a>