orgmode号称emacs下面的大杀器,emacs本来就是一个杀手级的应用,配上了orgmode真的是越用越爽。
新建文章
因为hugo目前渲染得比较好的还是md文件,因此我们通过ox-hugo来将org文件转成md文件,而且ox-hugo还能自动将文章导成md
目前组织文章的方式有两种:
- 一个文件就是一篇文章
- 一系列的文章放在一个文件里面,每一个一级标题就是一个文章
第一种其实就是第二种的一个特例,因此我选用了第二种来管理我的文章。
yasnippet自动补全
yasnippet是emacs里面的补全神器,我用的是doom-emacs的配置,因此在 ~/.doom.d/snippets/org-mode
里面新增了一个 __org-directory-template.org
文件
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
| # -*- mode: snippet -*-
# name: Org template for org directory
# --
# -*- mode: org; -*-
#+hugo_base_dir: ~/sys-cfg/github/vinurs.github.io/
#+hugo_section: ../content/post/`(file-name-nondirectory (directory-file-name (file-name-directory buffer-file-name)))`
#+startup: show2levels
* ${1:文章标题}
:PROPERTIES:
:export_title: ${2:导出的文章标齐}
:export_description: ${3:文章的描述}
:export_author: vinurs
:export_email: <[email protected]>
:export_date: `(format-time-string "%Y-%m-%d")`
:export_hugo_categories:
:export_hugo_tags: ${4:tag1} ${5:tag2}
:export_hugo_draft: true
:export_file_name: `(org-id-uuid)`
:export_hugo_auto_set_lastmod: t
:export_hugo_expirydate: 2999-01-01
:export_hugo_front_matter_key_replace: description>summary
:export_hugo_custom_front_matter: :from orgmode
:END:
${6:简介}
#+hugo: more
${0:文章正文}
** 更新历史
*** `(format-time-string "%Y/%m/%d")`
+ 初稿
* Footnotes
* COMMENT Local Variables :ARCHIVE:
# Local Variables:
# eval: (org-hugo-auto-export-mode -1)
# End:
|
参数解释:
:EXPORT_FILE_NAME:
导出的文件名称:EXPORT_TITLE:
文章的标题:EXPORT_DESCRIPTION
描述#+HUGO_SECTION:
导出的文件的目录更新历史
然后增加下面的配置函数,这个自动补全只对我用来记笔记的org文件才自动补全
1
2
3
4
5
| ;; 在org-directory下面的文件使用的org文件不一样
(set-file-template! "\\.org$"
:when '+org-file-in-org-directory-p
;; :when +file-templates-in-emacs-dirs-p
:trigger "__org-directory-template.org" :mode 'org-mode)
|
发布文章
每次我新建文章的时候,里面的 :EXPORT_HUGO_DRAFT:
的部分都是设置成了 false
,因此如果想发布文章,那么把这里改成 true
。
此外,我的文章是单独管理的,org文件没有放在github.io的仓库下面,因此每次我是保存到仓库目录下面,有些是我的draft文件,所以我不想把这些draft文件发布出去,因此我在仓库下面写了一个脚本每次只提交不是draft的文件。
重新生成md文件
目前我是通过ox-hugo来自动将org文件转成md文件,有时候我们将所有的文件重新生成一遍,这时候不需要重新一篇篇文章打开然后导出,ox-hugo里面提供了类似的方法。
同样地,为了方便管理,我fork了ox-hugo,将ox-hugo clone下来,然后修改里面的Makefile文件就可以了:
1
| git clone --recurse-submodules -j8 https://github.com/vinurs/ox-hugo.git
|
修改的内容如下:
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
| diff --git a/Makefile b/Makefile
index fc36596..45fe850 100644
--- a/Makefile
+++ b/Makefile
@@ -70,10 +70,12 @@ TEST_ENABLED=0
OX_HUGO_TEST_DIR=$(shell pwd)/test
# Base directory for the Hugo example site
-OX_HUGO_TEST_SITE_DIR=$(OX_HUGO_TEST_DIR)/site
+# OX_HUGO_TEST_SITE_DIR=$(OX_HUGO_TEST_DIR)/site
+OX_HUGO_TEST_SITE_DIR=~/sys-cfg/github/vinurs.github.io
# Directory containing Org files for the test site
-OX_HUGO_TEST_ORG_DIR=$(OX_HUGO_TEST_SITE_DIR)/content-org
+# OX_HUGO_TEST_ORG_DIR=$(OX_HUGO_TEST_SITE_DIR)/content-org
+OX_HUGO_TEST_ORG_DIR=~/sys-cfg/github/pkms
# https://stackoverflow.com/a/3774731/1219634
# Note that the use of immediate assignment := rather than recursive
# assignment = is important here: you do not want to be running the
diff --git a/test/setup-ox-hugo.el b/test/setup-ox-hugo.el
index d58f2db..cc57e42 100644
--- a/test/setup-ox-hugo.el
+++ b/test/setup-ox-hugo.el
@@ -198,6 +198,8 @@ Emacs installation. If Emacs is installed using
)
(require 'org-id)
+(require 'org-attach)
+
(require 'ox-hugo)
(defun org-hugo-export-all-wim-to-md ()
(org-hugo-export-wim-to-md :all-subtrees nil nil :noerror))
@@ -211,6 +213,9 @@ Emacs installation. If Emacs is installed using
(with-eval-after-load 'org
;; Allow multiple line Org emphasis markup
;; http://emacs.stackexchange.com/a/13828/115
+
+ (setq org-directory "~/sys-cfg/github/pkms/")
+ (setq org-attach-id-dir (expand-file-name ".attach/" org-directory))
(setcar (nthcdr 4 org-emphasis-regexp-components) 20) ;Up to 20 lines, default is just 1
;; Below is needed to apply the modified `org-emphasis-regexp-components'
;; settings from above.
|
OX_HUGO_TEST_SITE_DIR就是我们的github.io的目录,OX_HUGO_TEST_ORG_DIR是我们存放org文件的目录,然后进入ox-hugo目录,执行 make md
就可以重新生成。
增加新的插件
有时候我们orgmode里面用到的一些emacs的插件,可能ox-hugo里面没有包含,这就需要我们自己在里面进行添加配置,例如上面的org-attach,就包括添加了下面的代码
1
2
| (require 'org-attach)
(setq org-attach-id-dir (expand-file-name ".attach/" org-directory))
|
更新历史
- 2020-04-25
- 2020-04-19
- 2020-02-14
文章作者
vinurs
上次更新
2021-04-16
(e54c915)
许可协议
署名 4.0 国际