用 org-mode 寫博客
很早就聽說有一包喚作 ox-hugo ,可以用 org-mode 來寫博客,但當時我不以為然。然而在我用 org 製作了个人主頁後,體驗了 org-mode 與 Emacs 的流暢集成後,我也習慣了 org-mode 的操作,再回到 Markdown 環境簡直像回到原始社會,必須要配置一下了,正好也為博客寫作找點新鮮感。
安裝方面很簡單,根著文檔走即可。
(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)
然後設置一下 Hugo 目錄的變量:
(setq org-hugo-base-dir "/home/verdant/blog/")
為了方便,我寫了一個 Org Capture 來快速創建新文章:
(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%?"))))
在 Capture Buffer 鍵入 b 就可以開始創建。
