From 4bffe7be039f58529f9feb87eec93bcecbad7524 Mon Sep 17 00:00:00 2001 From: verdant Date: Fri, 6 Feb 2026 16:47:02 +0800 Subject: fix: note link --- public/generate-tag-pages.html~ | 257 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 public/generate-tag-pages.html~ (limited to 'public/generate-tag-pages.html~') diff --git a/public/generate-tag-pages.html~ b/public/generate-tag-pages.html~ new file mode 100644 index 0000000..3893910 --- /dev/null +++ b/public/generate-tag-pages.html~ @@ -0,0 +1,257 @@ + + + + + + + +生成标签页面 + + + + + +
+

生成标签页面

+

+为niwa生成一个标签页面。 +

+ +
+
(defun niwa/generate-tag-pages ()
+  "Generate tag pages under notes/tags/ from #+filetags."
+  (interactive)
+  (let* ((root (expand-file-name "~/niwa"))
+         (notes-dir (expand-file-name "notes" root))
+         (tags-dir  (expand-file-name "notes/tags" root))
+         (table (make-hash-table :test 'equal)))
+    ;; 收集 tags
+    (dolist (file (directory-files notes-dir t "\\.org$"))
+      (unless (string-match-p "/index\\.org$" file)
+        (with-temp-buffer
+          (insert-file-contents file)
+          (when (re-search-forward "^#\\+filetags:[ \t]*\\(.*\\)$" nil t)
+            (dolist (tag (split-string (match-string 1) ":" t))
+              (push file (gethash tag table)))))))
+    ;; 写入 tags/*.org
+    (make-directory tags-dir t)
+    (maphash
+     (lambda (tag files)
+       (with-temp-file (expand-file-name (concat tag ".org") tags-dir)
+         (insert "#+title: #" tag "\n")
+         (insert "#+SETUPFILE: ../../template/setup/minimal.setup\n\n")
+         (dolist (f (delete-dups files))
+           (insert
+            (format "- [[file:../%s][%s]]\n"
+                    (file-name-nondirectory f)
+                    (with-temp-buffer
+                      (insert-file-contents f)
+                      (if (re-search-forward "^#\\+title:[ \t]*\\(.*\\)$" nil t)
+                          (match-string 1)
+                        (file-name-base f))))))))
+     table)))
+
+
+ +

+Tags: +

+ +
+ + -- cgit v1.2.3