技术选型
原本可以一直使用 WordPress 的,但是同时也越发觉着 CMS 系统的”臃肿”,当然,这是个人观点。程序员总是追求所谓的”高效”,原本还想用 MarkDown 的方式发布博客,不过随着探究的深入,最终还是选定 Org-mode 的方式,能够满足笔记与博客两者,算是兼得吧。
如何发布
编辑器当然是 Emacs 了,但编辑内容还是 vi 模式比较舒服,所以找到了 Evil 这个插件。当用 Emacs 编辑好文章后,M-x org-publish-project RET blog RET
即可,如果只有一个项目那就直接用 M-x org-publish-all RET
。
通过 git 保存源文件,通过 rsync 同步生成的文件。
本地配置
具体可以参见 Publishing Org-mode files to HTML 以及一些导出选项 Options for the exporters
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
| (require 'ox-publish) (setq org-publish-project-alist '( ("blog-notes" :base-directory "~/org/blog/notes/" :base-extension "org" :publishing-directory "~/org/html/" :recursive t :publishing-function org-html-publish-to-html :section-numbers nil ; 不显示段落数字 :auto-sitemap t ; 自动生成站点地图 :sitemap-filename "index.org" ; 站点地图的文件名 :sitemap-title "" ; 站点的标题 :sitemap-sort-files anti-chronologically ; 站点文件排序方式, 时间倒序 :sitemap-file-entry-format "%d %t" ; 站点文件的链接格式"时间 标题" :language "zh-CN" :author "" :html-doctype "html5" :html-preamble "<a href=\"index.html\">首页</a>" ; 导航栏内容 :html-postamble "" ; 评论栏内容, 可加载 Google 统计 :html-head "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/worg.css\"/>" ; 自定义 CSS ) ("blog-static" :base-directory "~/org/blog/assets/" :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf" :publishing-directory "~/org/html/" :recursive t :publishing-function org-publish-attachment ) ("blog" :components ("blog-notes" "blog-static")) )) (setq org-publish-use-timestamps-flag nil) ; 不使用时间戳标识
|
目录结构
1 2 3 4 5 6 7 8 9 10 11 12
| org ├── blog │ ├── assets │ │ ├── css │ │ │ └── worg.css │ │ └── img │ └── notes │ ├── about.org │ ├── how-to-publish-my-blog-notes.org │ ├── how-to-site-my-blog-server.org │ └── index.org └── html
|
排坑记录
更新的时候,遇到了”Skipping unmodified file …”这种问题,查了一通资料,根据 org-publish doesn’t republish if you delete the .html file 和 Using emacs org-mode, how to publish the unchanged files in a project 以及 将发布Org文件为HTML文件 给出的解决方案才明白,原来 Org-mode 使用 .org-timestamps 记录时间戳变更,如果想要将全部内容(包括未更改的)重新发布,有以下三种可选方式:
- 删除 .org-timestamps 目录
- 使用前缀强制发布,
C-u M-x
- 在配置文件中取消时间戳标识,
(setq org-publish-use-timestamps-flag nil)
为了方便以后发布,目前使用的是第3种方式。
参考链接