使用emacs的org-mode
Aug. 11, 2023
使用emacs的org-mode
对于emacser来说,使用org-mode来写作才是最幸福的事情,因此就有了这一部分。这一部分的绝大部分内容来自脚注2[2]中提到的文章,基本的配置过程和要点在文章中都已经说得很详细了,因此我在这里就简略地说几点。
因为Jekyll可以识别markdown文件和html文件,所以使用emacs的org-mode将org文件publish成html文件就是我们要做的。值得一提的是Jekyll-Bootstrap在本地调试时直接无视_posts目录下后缀为html的文件,虽然说肯定有办法改变这种行为,但我找了一会没找到就放弃了,加之Jekyll-Bootstrap在Jekyll的基础上又多加了一些东西,所以导致我并没有去使用Jekyll-Bootstrap以及使用了Jekyll-Bootstrap的博客模板。
我的方案:
建立一个目录,在其中建立两个子目录,一个名为 org ,一个名为 Jekyll 。后者是和username.Github.io这个repo对应的本地repo目录,前者是org格式的文章存放目录,注意org目录下再建立一个 _posts 目录,将文章存放到 org/_posts 下面,这样在执行 org-publish-project 时才能保证生成到指定目录。
使用org-mode 7.x。emacs23自带的org-mode版本为6.x,其中的bug会导致插入的front-matter在生成时发生错误。emacs24自带的org-mode工作良好。
org-mode的publish参数中一定要加上 :body-only t 否则就会生成完整的html文件,这不是我们想要的。
编写文章时,在头部添加front matter,如下
#+BEGIN_HTML
---
layout : post
title : 使用Github Pages服务建立个人博客
categories : IT
tags : Github emacs org-mode Jekyll
---
#+END_HTML
而不需要其他信息,并在之后编写正文。
我的publish配置(仅供参考)
(require 'org-publish)
(setq org-publish-project-alist
'(
("org-linusp"
;; Path to your org files.
:base-directory "~/blog/org/"
:base-extension "org"
;; Path to your Jekyll project.
:publishing-directory "~/blog/Jekyll/"
:recursive t
:publishing-function org-publish-org-to-html
:headline-levels 4
:html-extension "html"
:body-only t ;; Only export section between <body> </body>
)
("org-static-linusp"
:base-directory "~/blog/org/"
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|php"
:publishing-directory "~/blog/Jekyll/"
:recursive t
:publishing-function org-publish-attachment
)
("blog-linusp" :components ("org-linusp" "org-static-linusp"))
))
执行 org-publish-project 时,选择 blog-linusp 进行publish(按照我这个配置)。