<h2>目录</h2><ul>
<li><a href="#orgheadline6">1. emacs 在线博客系统搭建</a> <ul>
<li><a href="#orgheadline1">1.1. org->html</a></li>
<li><a href="#orgheadline4">1.2. org->PDF</a> <ul>
<li><a href="#orgheadline2">1.2.1. 修改tex命令使用xelatex, 添加需要的package</a></li>
<li><a href="#orgheadline3">1.2.2. org文件头自动添加</a></li> </ul> </li>
<li><a href="#orgheadline5">1.3. org mode 功能强化(截图自动插入)</a></li> </ul> </li> </ul>
转自我的GitHub博客
如果你觉得还不错,欢迎点赞.
本文所有的环境基于
- 软件: Ubuntu 16.04
- 硬件: Thinkpad W530
emacs 在线博客系统搭建<a id="orgheadline6"></a>
前段时间利用emacs orgmode和Github.io来搭建个人技术博客 .
实质上github page的个人博客站点只是一个Github上一个个人项目,项目文件夹根目录下有个index.html即可实现个人站点.结合Orgmode导出 HTML可以轻松对Blog内容进行管理, 加上Git的版本控制, 几乎可以说是个人静态站点的完美实现方案.
我的个人实现需求和实现方案.
org mode -> html(在线发布)/pdf(本地存档)/markdown(简书之流) -> push到gitHub(版本管理和在线存储)
org->html<a id="orgheadline1"></a>
我选用了orgmode的一个theme文件 theme-readtheorg.setup, 并且在org文件头添加
#+SETUPFILE: theme-readtheorg.setup
这样org就可以导出非常漂亮的html文件, 缺点是html页面加载较慢. 效果如下:
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://orgmode.org/worg/worg.css" />
这样html采用了orgmode的官方手册的css, 排版简洁,清爽, 加载速度快.效果如下:
org->PDF<a id="orgheadline4"></a>
使用linux下的xelate直接把org文件导出成精致的pdf, 效果如下:
需要在.spacemacs添加如下配置:
修改tex命令使用xelatex, 添加需要的package<a id="orgheadline2"></a>
(setq org-latex-packages-alist
'(("" "graphicx" t)
("" "longtable" nil)
("" "float" nil)))
;; source: https://lists.gnu.org/archive/html/emacs-orgmode/2013-06/msg00240.html
(defun my-auto-tex-cmd (backend)
"when exporting from .org with latex,
automatically run latex, pdflatex, or xelatex as appropriate,
using latexmk."
(let ((texcmd))
(setq texcmd "latexmk -pdf %f")
(if (string-match "LATEX_CMD: pdflatex" (buffer-string))
(progn
(setq texcmd "latexmk -pdf -pdflatex='pdflatex -file-line-error --shell-escape -synctex=1' %f")
(setq org-latex-default-packages-alist
'(("AUTO" "inputenc" t)
("T1" "fontenc" t)
("" "fixltx2e" nil)
("" "wrapfig" nil)
("" "soul" t)
("" "textcomp" t)
("" "marvosym" t)
("" "wasysym" t)
("" "latexsym" t)
("" "amssymb" t)
("" "hyperref" nil)))))
(if (string-match "LATEX_CMD: xelatex" (buffer-string))
(progn
(setq texcmd "latexmk -pdflatex='xelatex -file-line-error --shell-escape -synctex=1' -pdf %f")
(setq org-latex-default-packages-alist
'(("" "fontspec" t)
("" "xunicode" t)
("" "url" t)
("" "rotating" t)
("" "fancyhdr" t)
("" "lastpage" t)
;; ("" "memoir-article-styles" nil)
("american" "babel" t)
("babel" "csquotes" t)
("" "listings" t)
("svgnames" "xcolor" t)
("" "soul" t)
("xetex, colorlinks=true, urlcolor=FireBrick, plainpages=false, pdfpagelabels, bookmarksnumbered" "hyperref" nil)
))
(setq org-latex-classes
(cons '("memarticle"
"\\documentclass[11pt,oneside,article]{memoir}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
org-latex-classes))))
(setq org-latex-pdf-process (list texcmd))))
(add-hook 'org-export-before-parsing-hook 'my-auto-tex-cmd)
org文件头自动添加<a id="orgheadline3"></a>
(eval-after-load 'autoinsert
'(define-auto-insert
'("\\.org\\'" . "org header")
'("Add export params"
"#+TITLE: " (file-name-nondirectory (buffer-file-name))\n
"#+AUTHOR: 林晨<lc1990linux@gmail.com>" \n
"#+LATEX_CMD: xelatex" \n
"#+LATEX_HEADER: \\setmainfont{Adobe Kaiti Std}" \n
"#+LATEX_HEADER: \\XeTeXlinebreaklocale \"zh\"" \n
"#+LATEX_HEADER: \\XeTeXlinebreakskip = 0pt plus 1pt" \n
"#+LATEX_HEADER: \\definecolor{softgreen}{rgb}{0.78,0.93,0.8}" \n
"#+LATEX_HEADER: \\pagecolor{softgreen}" \n
"#+LATEX_HEADER: \\pagestyle{fancy}" \n
"#+LATEX_HEADER: \\lhead{page \\thepage\\ of \\pageref{LastPage}}" \n
"#+LATEX_HEADER: \\rhead{\\small\\leftmark}" \n
"#+LATEX_HEADER: \\cfoot{\\thepage}" \n
"#+LATEX_HEADER: \\renewcommand{\\headrulewidth}{1pt}" \n
"#+LATEX_HEADER: \\setlength{\\skip\\footins}{0.5cm}" \n
"#+LATEX_HEADER: \\renewcommand{\\footnotesize}{}" \n
"#+LATEX_HEADER: \\renewcommand{\\footrulewidth}{1pt}" \n
"#+SETUPFILE: theme-readtheorg.setup" \n \n
> _ \n)))
org mode 功能强化(截图自动插入)<a id="orgheadline5"></a>
(defun my-org-screenshot ()
"Take a screenshot into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file."
(interactive)
(org-display-inline-images)
(setq filename
(concat
(make-temp-name
(concat (file-name-nondirectory (buffer-file-name))
"_imgs/"
(format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
(unless (file-exists-p (file-name-directory filename))
(make-directory (file-name-directory filename)))
; take screenshot
(if (eq system-type 'darwin)
(call-process "screencapture" nil nil nil "-i" filename))
(if (eq system-type 'gnu/linux)
(call-process "import" nil nil nil filename))
; insert into file if correctly taken
(if (file-exists-p filename)
(insert (concat "[[file:" filename "]]"))))