Commit 2e36529

HPCesia <me@hpcesia.com>
2026-02-09 18:13:33
Clean useless endnotes using rehype plugin.
1 parent 5cb2d2a
src/plugins/rehype-clean-endnotes.ts
@@ -0,0 +1,16 @@
+import type { RehypePlugin } from "@astrojs/markdown-remark";
+import { visit } from "unist-util-visit";
+
+// Clean auto generated endnote, because we generate sidenotes instead.
+export const rehypeCleanEndnotes: RehypePlugin = () => (tree) => {
+  visit(tree, "element", (node, index, parent) => {
+    if (
+      node.tagName === "section" &&
+      node.properties.role === "doc-endnotes" &&
+      parent &&
+      typeof index === "number"
+    ) {
+      parent.children.splice(index, 1);
+    }
+  });
+};
src/styles/article/sidenote.css
@@ -8,7 +8,3 @@
     @apply pl-4;
   }
 }
-
-section[role="doc-endnotes"] {
-  @apply hidden;
-}
astro.config.ts
@@ -2,6 +2,7 @@ import tailwindcss from "@tailwindcss/vite";
 import { defineConfig } from "astro/config";
 import { SITE_CONFIG } from "./src/config";
 import { typst } from "astro-typst";
+import { rehypeCleanEndnotes } from "./src/plugins/rehype-clean-endnotes";
 
 // https://astro.build/config
 export default defineConfig({
@@ -14,6 +15,9 @@ export default defineConfig({
       target: "html",
     }),
   ],
+  markdown: {
+    rehypePlugins: [rehypeCleanEndnotes],
+  },
   vite: {
     plugins: [tailwindcss()],
     ssr: {
package.json
@@ -9,13 +9,15 @@
     "astro": "astro"
   },
   "dependencies": {
+    "@astrojs/markdown-remark": "^6.3.10",
     "@myriaddreamin/typst-ts-node-compiler": "^0.7.0-rc2",
     "@myriaddreamin/typst-ts-renderer": "^0.7.0-rc2",
     "@myriaddreamin/typst.ts": "0.7.0-rc2",
     "@tailwindcss/vite": "^4.1.18",
     "astro": "^5.17.1",
     "astro-typst": "^0.12.3",
-    "tailwindcss": "^4.1.18"
+    "tailwindcss": "^4.1.18",
+    "unist-util-visit": "^5.1.0"
   },
   "devDependencies": {
     "@biomejs/biome": "^2.3.13"
pnpm-lock.yaml
@@ -8,6 +8,9 @@ importers:
 
   .:
     dependencies:
+      '@astrojs/markdown-remark':
+        specifier: ^6.3.10
+        version: 6.3.10
       '@myriaddreamin/typst-ts-node-compiler':
         specifier: ^0.7.0-rc2
         version: 0.7.0-rc2
@@ -29,6 +32,9 @@ importers:
       tailwindcss:
         specifier: ^4.1.18
         version: 4.1.18
+      unist-util-visit:
+        specifier: ^5.1.0
+        version: 5.1.0
     devDependencies:
       '@biomejs/biome':
         specifier: ^2.3.13