summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <eltrac@vmi3030963.contaboserver.net>2026-02-10 13:41:13 +0800
committerEltrac <eltrac@vmi3030963.contaboserver.net>2026-02-10 13:41:13 +0800
commit5e53a9d0353a0f27c05b8e9cc423e35707dc0ba1 (patch)
tree8b30244506bb0a3ddb1a62376555a6b26ff24ae4
parent68a47328129540fdd8bda1fadfa71617edca4035 (diff)
parent1b844f1230a03983bf027a321eb77bb908f469ea (diff)
Merge branch 'master' of https://src.eltr.ac/eltrac/geedeapro
-rw-r--r--assets/js/inject-footnotes.js36
-rw-r--r--layouts/_partials/content.html9
-rw-r--r--layouts/_partials/scripts.html1
-rw-r--r--layouts/_partials/template/post-page.html9
-rw-r--r--layouts/_partials/utils/inject-footnotes.html44
-rw-r--r--layouts/_partials/utils/render.html1
-rw-r--r--layouts/fictions/page.html12
-rw-r--r--layouts/library/page.html6
8 files changed, 59 insertions, 59 deletions
diff --git a/assets/js/inject-footnotes.js b/assets/js/inject-footnotes.js
deleted file mode 100644
index 20086ea6..00000000
--- a/assets/js/inject-footnotes.js
+++ /dev/null
@@ -1,36 +0,0 @@
-document.addEventListener("DOMContentLoaded", () => {
- const refs = Array.from(document.querySelectorAll("sup[id^='fnref']"));
- // reverse traversal, to keep injected footnotes in order
- for (let i = refs.length - 1; i >= 0; i--) {
- const ref = refs[i];
-
- const noteNumber = i + 1;
- const noteId = ref.id.replace("fnref", "fn");
- const note = document.getElementById(noteId);
-
- if (note) {
- // construct note element
- const inline = document.createElement("div");
- inline.className = "text-sm text-secondary flex gap-2 ml-4";
-
- const footnoteNumber = document.createElement('span')
- footnoteNumber.textContent = noteNumber;
- const footnoteContent = document.createElement('div');
- footnoteContent.innerHTML = note.innerHTML;
-
- inline.appendChild(footnoteNumber);
- inline.appendChild(footnoteContent);
- inline.id = noteId;
-
- // insert adjacent to paragraph
- // if it's inside a table, then insert outside the table
- if (ref.closest('table')) {
- ref.closest('table').insertAdjacentElement("afterend", inline);
- } else {
- ref.parentNode.insertAdjacentElement("afterend", inline);
- }
- }
- }
- // remove original footnotes
- document.getElementsByClassName("footnotes")[0]?.remove()
-});
diff --git a/layouts/_partials/content.html b/layouts/_partials/content.html
new file mode 100644
index 00000000..e1baae34
--- /dev/null
+++ b/layouts/_partials/content.html
@@ -0,0 +1,9 @@
+<div class="min-h-[60%] leading-loose mb-8 markdown-body text-size-md md:text-size-lg"
+ style="view-transition-name: post-content-{{ .File.UniqueID }}">
+ {{ partial "posts/toc" . }}
+ <div id="post-content">
+ {{ partial "utils/render" .Content }}
+ </div>
+ {{ partial "posts/endnotes" . }}
+</div>
+
diff --git a/layouts/_partials/scripts.html b/layouts/_partials/scripts.html
index 718d7477..6ad03632 100644
--- a/layouts/_partials/scripts.html
+++ b/layouts/_partials/scripts.html
@@ -10,7 +10,6 @@
{{ if not .IsHome }}
{{ $articleJS := slice
(resources.Get "js/toc.js")
- (resources.Get "js/inject-footnotes.js")
(resources.Get "js/back2top.js")
(resources.Get "js/fediform.js")
}}
diff --git a/layouts/_partials/template/post-page.html b/layouts/_partials/template/post-page.html
index b05b6b41..d25b50fe 100644
--- a/layouts/_partials/template/post-page.html
+++ b/layouts/_partials/template/post-page.html
@@ -35,14 +35,7 @@
</div>
</header>
- <!-- Post Content -->
- <div class="min-h-[60%] leading-loose mb-8 markdown-body text-size-md md:text-size-lg"
- style="view-transition-name: post-content-{{ .File.UniqueID }}">
- {{ partial "posts/toc" . }}
- <div id="post-content">{{ .Content }}</div>
- {{ partial "posts/endnotes" . }}
- </div>
-
+ {{ partial "content" . }}
{{ partial "posts/action-menu.html" . }}
{{ partial "components/back-to-top.html" . }}
</article>
diff --git a/layouts/_partials/utils/inject-footnotes.html b/layouts/_partials/utils/inject-footnotes.html
new file mode 100644
index 00000000..57cc1e00
--- /dev/null
+++ b/layouts/_partials/utils/inject-footnotes.html
@@ -0,0 +1,44 @@
+{{ $content := . }}
+
+{{ $footnotesPattern := `(?s)<div class="footnotes"[^>]*>.*?</div>` }}
+{{ $footnotesMatch := findRE $footnotesPattern $content 1 }}
+
+{{ if $footnotesMatch }}
+ {{ $footnotesSection := index $footnotesMatch 0 }}
+
+ {{ $liPattern := `(?s)<li id="fn:(\d+)">(.*?)</li>` }}
+ {{ $footnoteItems := findRESubmatch $liPattern $footnotesSection }}
+
+ {{ $footnoteMap := dict }}
+ {{ range $footnoteItems }}
+ {{ $id := index . 1 }}
+ {{ $contentRaw := index . 2 }}
+ {{ $cleanContent := replaceRE `(?s)\s*<a href="#fnref:\d+"[^>]*>.*?</a>\s*$` "" $contentRaw }}
+ {{ $footnoteMap = merge $footnoteMap (dict $id $cleanContent) }}
+ {{ end }}
+
+ {{ $contentWithoutFootnotes := replaceRE $footnotesPattern "" $content }}
+
+ {{ $refPattern := `<sup id="fnref:(\d+)".*?</sup>` }}
+ {{ $refs := findRESubmatch $refPattern $contentWithoutFootnotes }}
+
+ {{ $result := $contentWithoutFootnotes }}
+ {{ $count := len $refs }}
+
+ {{ range seq (sub $count 1) -1 0 }}
+ {{ $ref := index $refs . }}
+ {{ $refFull := index $ref 0 }}
+ {{ $refId := index $ref 1 }}
+ {{ $noteContent := index $footnoteMap $refId }}
+
+ {{ if $noteContent }}
+ {{ $inlineFootnote := printf `<div class="inline-footnote text-sm text-secondary flex gap-2 ml-4 mt-2 mb-2" id="fn:%s"><span>%s.</span><div>%s</div></div>` $refId $refId $noteContent }}
+ {{ $replacement := printf `%s%s` $refFull $inlineFootnote }}
+ {{ $result = replace $result $refFull $replacement 1 }}
+ {{ end }}
+ {{ end }}
+
+ {{ $content = $result }}
+{{ end }}
+
+{{ $content | safeHTML }}
diff --git a/layouts/_partials/utils/render.html b/layouts/_partials/utils/render.html
new file mode 100644
index 00000000..bdc4bf2f
--- /dev/null
+++ b/layouts/_partials/utils/render.html
@@ -0,0 +1 @@
+{{ partial "utils/inject-footnotes" . }}
diff --git a/layouts/fictions/page.html b/layouts/fictions/page.html
index 81e74f2e..1b5b400d 100644
--- a/layouts/fictions/page.html
+++ b/layouts/fictions/page.html
@@ -1,6 +1,5 @@
{{ define "main" }}
<article>
- <!-- Post Header -->
<header class="text-center">
{{ partial "components/logo" (dict
"link" "fictions/"
@@ -16,13 +15,8 @@
<div class="text-secondary">{{ partial "components/date" . }}</div>
</header>
- <!-- Post Content -->
- <div id="post-content" class="post-content markdown-body text-size-lg md:text-size-xl leading-loose"
- style="view-transition-name: post-content-{{ .File.UniqueID }}">
- {{ .Content }}
- </div>
-
- {{ partial "posts/action-menu.html" . }}
- {{ partial "components/back-to-top.html" . }}
+ {{ partial "content" . }}
+ {{ partial "posts/action-menu.html" . }}
+ {{ partial "components/back-to-top.html" . }}
</article>
{{ end }}
diff --git a/layouts/library/page.html b/layouts/library/page.html
index 310b19a7..9da6e683 100644
--- a/layouts/library/page.html
+++ b/layouts/library/page.html
@@ -28,11 +28,7 @@
</p>
</header>
- <div class="markdown-body leading-loose text-size-lg md:text-size-xl">
- {{ partial "posts/toc" . }}
- <div>{{ .Content }}</div>
- {{ partial "posts/endnotes" . }}
- </div>
+ {{ partial "content" . }}
<div class="text-size-base text-secondary md:flex md:justify-between">
<p>于 {{ partial "components/date" . }} 读完</p>