利用org-mode和org2jekyll在github pages上部署博客

环境

  • jekyll

    本人的环境是mac,在jekyll的官方网站就介绍了安装方法,命令为 gem install jekyll

  • org2jekyll

    利用emacs自身的安装工具,执行 M-x package-install RET org2jekyll

  • github pages

    在github中创建一个pages,具体方法点击这里,简单易操作

配置

  • org2jekyll

    org2jekyll的项目主页介绍了配置

    我配置时没有成功,就在 .emacs 文件中直接编辑的,如下:

    (require 'org)
    (require 'org2jekyll)
    
    (custom-set-variables '(org2jekyll-blog-author "sars715")
    		      '(org2jekyll-source-directory (expand-file-name "~/org/"))
    		      '(org2jekyll-jekyll-directory (expand-file-name "~/github/sars715.github.io/"))
    		      '(org2jekyll-jekyll-drafts-dir "")
    		      '(org2jekyll-jekyll-posts-dir "_posts/")
    		      '(org-publish-project-alist
    			`(("default"
    			   :base-directory ,(org2jekyll-input-directory)
    			   :base-extension "org"
    			   :publishing-directory ,(org2jekyll-output-directory)
    			   :publishing-function org-html-publish-to-html
    			   :headline-levels 4
    			   :section-numbers nil
    			   :with-toc nil
    			   :html-head "<link rel=\"stylesheet\" href=\"./css/style.css\" type=\"text/css\"/>"
    			   :html-preamble t
    			   :recursive t
    			   :make-index t
    			   :html-extension "html"
    			   :body-only t)
    			  ("post"
    			   :base-directory ,(org2jekyll-input-directory)
    			   :base-extension "org"
    			   :publishing-directory ,(org2jekyll-output-directory org2jekyll-jekyll-posts-dir)
    			   :publishing-function org-html-publish-to-html
    			   :headline-levels 4
    			   :section-numbers nil
    			   :with-toc nil
    			   :html-head "<link rel=\"stylesheet\" href=\"./css/style.css\" type=\"text/css\"/>"
    			   :html-preamble t
    			   :recursive t
    			   :make-index t
    			   :html-extension "html"
    			   :body-only t)
    			  ("images"
    			   :base-directory ,(org2jekyll-input-directory "img")
    			   :base-extension "jpg\\|gif\\|png"
    			   :publishing-directory ,(org2jekyll-output-directory "img")
    			   :publishing-function org-publish-attachment
    			   :recursive t)
    			  ("js"
    			   :base-directory ,(org2jekyll-input-directory "js")
    			   :base-extension "js"
    			   :publishing-directory ,(org2jekyll-output-directory "js")
    			   :publishing-function org-publish-attachment
    			   :recursive t)
    			  ("css"
    			   :base-directory ,(org2jekyll-input-directory "css")
    			   :base-extension "css\\|el"
    			   :publishing-directory ,(org2jekyll-output-directory "css")
    			   :publishing-function org-publish-attachment
    			   :recursive t)
    			  ("web" :components ("images" "js" "css")))))
    

部署

打开一个emacs的buffer,输入 M-x org2jekyll-create-draft 即可按步骤创建新的post

写好一个post后,输入 M-x orgjekyll-publish 即可部署该篇post