From 8854c18002a72d35da281f76ef7ec5b9c57981fc Mon Sep 17 00:00:00 2001 From: verdant Date: Fri, 24 Jul 2026 03:58:23 +0800 Subject: Post 用 org-mode 寫博客 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...g-mode\345\257\253\345\215\232\345\256\242.org" | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "org/\347\224\250org-mode\345\257\253\345\215\232\345\256\242.org" (limited to 'org') diff --git "a/org/\347\224\250org-mode\345\257\253\345\215\232\345\256\242.org" "b/org/\347\224\250org-mode\345\257\253\345\215\232\345\256\242.org" new file mode 100644 index 0000000..966d39e --- /dev/null +++ "b/org/\347\224\250org-mode\345\257\253\345\215\232\345\256\242.org" @@ -0,0 +1,42 @@ +#+title: 用 org-mode 寫博客 +#+date: 2026-07-18 +#+hugo_categories: 技术 +#+hugo_tags: Emacs org-mode Hugo +#+hugo_custom_front_matter: :showMeta true +#+hugo_custom_front_matter: :org true + +很早就聽說有一包喚作 =ox-hugo= ,可以用 org-mode 來寫博客,但當時我不以為然。然而在我用 org 製作了个人主頁後,體驗了 org-mode 與 Emacs 的流暢集成後,我也習慣了 org-mode 的操作,再回到 Markdown 環境簡直像回到原始社會,必須要配置一下了,正好也為博客寫作找點新鮮感。 + +安裝方面很簡單,根著文檔走即可。 + +#+begin_src emacs-lisp +(use-package ox-hugo + :ensure t ;Auto-install the package from Melpa + :pin melpa ;`package-archives' should already have ("melpa" . "https://melpa.org/packages/") + :after ox) +#+end_src + +然後設置一下 Hugo 目錄的變量: + +#+begin_src +(setq org-hugo-base-dir "/home/verdant/blog/") +#+end_src + +為了方便,我寫了一個 Org Capture 來快速創建新文章: + +#+begin_src emacs-lisp +(with-eval-after-load 'org-capture +(setq org-capture-templates + '(("b" "New blog post" plain + (file (lambda () + (let ((slug (read-string "Post Slug (如 my-post): "))) + (expand-file-name + (format-time-string (concat slug ".org")) + "/home/verdant/blog/org/")))) + "#+title: %^{文章標題}\n#+date: %<%Y-%m-%d>\n#+hugo_categories: %^{分類}\n#+hugo_tags: %^{標籤}\n#+hugo_custom_front_matter: :showMeta true\n\n%?")))) +#+end_src + +在 Capture Buffer 鍵入 =b= 就可以開始創建。 + +[[https://images.verdant.ee/2026-07-18_19-13.gif]] + -- cgit v1.2.3