blob: 4c3a697f42d7627d18663ed71d5e570287b925ac (
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
43
44
45
|
+++
title = "用 org-mode 寫博客"
author = ["Verdant"]
date = 2026-07-18
tags = ["Emacs", "org-mode", "Hugo"]
categories = ["技术"]
draft = false
showMeta = true
org = true
+++
很早就聽說有一包喚作 `ox-hugo` ,可以用 org-mode 來寫博客,但當時我不以為然。然而在我用 org 製作了个人主頁後,體驗了 org-mode 與 Emacs 的流暢集成後,我也習慣了 org-mode 的操作,再回到 Markdown 環境簡直像回到原始社會,必須要配置一下了,正好也為博客寫作找點新鮮感。
安裝方面很簡單,根著文檔走即可。
```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)
```
然後設置一下 Hugo 目錄的變量:
```nil
(setq org-hugo-base-dir "/home/verdant/blog/")
```
為了方便,我寫了一個 Org Capture 來快速創建新文章:
```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%?"))))
```
在 Capture Buffer 鍵入 `b` 就可以開始創建。
{{< figure src="https://images.verdant.ee/2026-07-18_19-13.gif" >}}
|