blob: 966d39e452622ab8488185fef991932e891d2994 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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]]
|