用 =org mode= 写一个本地静态网站
Table of Contents
1. 用途
工作中,文档写的很多,全部导出成 pdf 发出去,也会比较麻烦。所以萌生了本地起一个 web 服务, 直接发链接给内网同事的想法。更新起来也方便。
2. 步骤
利用 org mode 的 publish 功能,配置步骤如下:
- 本地起一个 web 服务器(比如 nginx)即可
- 配置 org-mode 的发布
- 配置静态资源的发布
- 配置 org 文档的发布
3. web 服务器
brew install nginx
mac 下,默认的静态目录为: /usr/local/var/www
4. 配置 org-mode 的 project
修改参数: org-publish-project-alist 即可。
4.1. 配置静态资源的发布
("org-agora-static"
:base-directory "~/Documents/agora/"
:base-extension "gz\\|eps\\|css\\|js\\|png\\|jpg\\|gif\\|mp3\\|ogg\\|swf"
:publishing-directory "/usr/local/var/www"
:recursive t
:publishing-function org-publish-attachment
)
4.2. 配置 org 目录的发布
("org-agora-notes"
:base-directory "~/Documents/agora/"
:base-extension "org"
:publishing-directory "/usr/local/var/www"
:recursive t
:publishing-function org-html-publish-to-html
:headline-levels 3 ; Just the default for this project.
:auto-preamble t
:auto-sitemap t ; Generate sitemap.org automagically...
:sitemap-filename "index.org" ; ... call it sitemap.org (it's the default)...
:sitemap-format-entry org-sitemap-custom-entry-format
:html-link-home "/"
:sitemap-title "文档列表" ; ... with title 'Sitemap'.
:section-numbers nil
:table-of-contents 2
:sitemap-filename "index.org"
:sitemap-sort-files anti-chronologically
:exclude "index.org"
:html-head-extra "<link rel='stylesheet' type='text/css' href='../styles/readtheorg/css/htmlize.css'/><link rel='stylesheet' type='text/css' href='../styles/readtheorg/css/readtheorg.css'/>"
)
4.3. 配置 index 文件的发布
("org-agora-index"
:base-directory "~/Documents/agora/"
:base-extension "org"
:exclude ".*"
:include ["index.org"]
:publishing-directory "/usr/local/var/www"
:publishing-function org-html-publish-to-html
:table-of-contents nil
:html-head-extra "<link rel='stylesheet' type='text/css' href='styles/readtheorg/css/htmlize.css'/><link rel='stylesheet' type='text/css' href='styles/readtheorg/css/readtheorg.css'/>"
)
4.4. 配置总项目
("org-agora" :components ("org-agora-notes" "org-agora-static" "org-agora-index" ))
4.5. 配置项目的样式文件
拷贝 https://github.com/fniessen/org-html-themes 的样式文件至: ~/Documents/agora/ (以自己的配置为准)
5. 汇总配置
(require 'ox-publish)
(setq org-publish-project-alist
'(
("org-agora-index"
:base-directory "~/Documents/agora/"
:base-extension "org"
:exclude ".*"
:include ["index.org"]
:publishing-directory "/usr/local/var/www"
:publishing-function org-html-publish-to-html
:table-of-contents nil
:html-head-extra "<link rel='stylesheet' type='text/css' href='styles/readtheorg/css/htmlize.css'/><link rel='stylesheet' type='text/css' href='styles/readtheorg/css/readtheorg.css'/>"
)
("org-agora-notes"
:base-directory "~/Documents/agora/"
:base-extension "org"
:publishing-directory "/usr/local/var/www"
:recursive t
:publishing-function org-html-publish-to-html
:headline-levels 3 ; Just the default for this project.
:auto-preamble t
:auto-sitemap t ; Generate sitemap.org automagically...
:sitemap-filename "index.org" ; ... call it sitemap.org (it's the default)...
:sitemap-format-entry org-sitemap-custom-entry-format
:html-link-home "/"
:sitemap-title "文档列表" ; ... with title 'Sitemap'.
:section-numbers nil
:table-of-contents 2
:sitemap-filename "index.org"
:sitemap-sort-files anti-chronologically
:exclude "index.org"
:html-head-extra "<link rel='stylesheet' type='text/css' href='../styles/readtheorg/css/htmlize.css'/><link rel='stylesheet' type='text/css' href='../styles/readtheorg/css/readtheorg.css'/>"
)
("org-agora-static"
:base-directory "~/Documents/agora/"
:base-extension "gz\\|eps\\|css\\|js\\|png\\|jpg\\|gif\\|mp3\\|ogg\\|swf"
:publishing-directory "/usr/local/var/www"
:recursive t
:publishing-function org-publish-attachment
)
("org-agora" :components ("org-agora-notes" "org-agora-static" "org-agora-index" ))
))
6. 发布样例
图片稍后补充