diff options
| author | verdant <i@glowisle.me> | 2026-02-06 16:47:02 +0800 |
|---|---|---|
| committer | verdant <i@glowisle.me> | 2026-02-06 16:47:02 +0800 |
| commit | 4bffe7be039f58529f9feb87eec93bcecbad7524 (patch) | |
| tree | e104a78ad800286c32de240d11f47c956a1d8469 /notes | |
| parent | 327797a634a5b8fe5acbd9063e734da0ffaaa095 (diff) | |
| download | niwa-4bffe7be039f58529f9feb87eec93bcecbad7524.tar.gz niwa-4bffe7be039f58529f9feb87eec93bcecbad7524.zip | |
fix: note link
Diffstat (limited to 'notes')
| -rw-r--r-- | notes/generate-tag-pages.org | 45 | ||||
| -rw-r--r-- | notes/test.org | 7 |
2 files changed, 52 insertions, 0 deletions
diff --git a/notes/generate-tag-pages.org b/notes/generate-tag-pages.org new file mode 100644 index 0000000..f2e3238 --- /dev/null +++ b/notes/generate-tag-pages.org @@ -0,0 +1,45 @@ +#+title: 生成标签页面 +#+SETUPFILE: ~/niwa/template/setup/minimal.setup +#+filetags: :emacs:technology: +#+EXPORT_FILE_NAME: /home/yingyu5658/niwa/public/generate-tag-pages.html + +为niwa生成一个标签页面。 + +#+BEGIN_SRC elisp +(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))) +#+END_SRC + +Tags: +- [[/tags/emacs][Emacs]] +- [[/tags/technology][Technology]] diff --git a/notes/test.org b/notes/test.org new file mode 100644 index 0000000..57067dd --- /dev/null +++ b/notes/test.org @@ -0,0 +1,7 @@ +#+title: Title +#+SETUPFILE: ~/niwa/template/setup/minimal.setup +#+EXPORT_FILE_NAME: /home/yingyu5658/niwa/public/test.html + + + +** Content |
