Table of Contents

1. 发布站点 by emacs org-mode

org-mode 写文档做笔记啥的很方便, 反应超快(因为是文本文件), 而且在emacs中可以显示出类似word的效果. 但是给没有emacs的人看时, 就不太方便.(没有高亮显示, 也无法在文本中跳转等等)

为了将继续使用 org-mode 带来的便利, 也为了方便别人查看自己的文档, 稍稍调查了一下org-mode导出html的功能.

1.1 org-mode 自带的导出方法

强大的org-mode其实自带了导出各种格式的功能. 导出html格式的快捷键很简单:

C-c C-e h

虽然方便, 但是导出的html格式不太好看, 而且不能批量导出, 这个命令只能导出一个org文件.

1.2 批量导出

org-mode虽然也有导出org project的命令, 但是需要在 .emacs中配置相关导出选项. 每次导出不同的项目时, 需要修改 .emacs, 修改 .emacs后要么重新导入, 要么重启 emacs. 总觉得很麻烦.

后来参考了博客园上[麦满屯]的一篇博客1, 用Makefile来简化 org 文件的导出和发布. Makefile如下:

EMACS=emacsclient   # 这里我用的emcasclient, 没有用emacs. 因为我的emacs是以server方式启动的
ORG_CONFIG_FILE=publish-config.el # 导出org文件的配置
EMACS_OPTS=--eval "(load-file \"$(ORG_CONFIG_FILE)\")" DEST_HOST='myhost.com:public_html/'
OUTPUT_DIR=~/tmp/output # 导出的位置, 这个位置其实是在 public-config.el 中配置的,
# 这里的定义这个变量的作用是为了删除(make clean), 以及上传server(make upload) all: html upload html:
@echo "Generating HTML..."
@mkdir -p $(OUTPUT_DIR)
@$(EMACS) $(EMACS_OPTS)
@echo "HTML generation done" upload:
@cd $(OUTPUT_DIR) && scp -r . $(DEST_HOST) && cd .. clean:
@rm -rf $(OUTPUT_DIR)

仅仅导出html, 而不发布站点, 只要用:

make html

其中用的配置文件 publish-config.el 如下: 主要参考了[麦满屯]的一篇博客1

;; config for publish site from org files
(require 'org-publish) (setq org-publish-project-alist
'(
;; These are the main web files
("org-notes"
:base-directory "~/tmp/www/" ;; Change this to your local dir
:base-extension "org"
:publishing-directory "~/tmp/output"
:recursive t
:publishing-function org-publish-org-to-html
:headline-levels 4 ; Just the default for this project.
:auto-preamble nil
:auto-sitemap t
:sitemap-filename "sitemap.org"
:sitemap-title "sitemap"
:section-numbers nil
:table-of-contents t
:style "<link rel='stylesheet' type='text/css' href='css/org-manual.css' />"
:style-include-default nil
) ;; These are static files (images, pdf, etc)
("org-static"
:base-directory "~/tmp/www/" ;; Change this to your local dir
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|txt\\|asc"
:publishing-directory "~/tmp/output"
:recursive t
:publishing-function org-publish-attachment
) ("org" :components ("org-notes" "org-static"))
)
) (defun myweb-publish nil
"Publish myweb."
(interactive)
(org-publish-all)) (myweb-publish)

注意上面的配置文件中引用了一个 css 文件 org-manual.css 这是因为默认导出的html文件格式实在是… …

1.3 css 美化

css的使用方法主要参考的了 HE QIN 同学的说明2, 说明的很详细, 我参照着她的说明简化了一下, 暂时只有css, 没有引入 javascript. 这个 org-manual.css 的样式是直接从 org-mode 的官方说明3 上直接下载下来的, 因为我觉得官方的使用说明的样式还挺简洁.(特别是右上角的内容导航很酷 ^_^) org-manual.css内容如下:

@import url(http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans+Mono|Droid+Serif);

html {
padding: 0;
} body {
font-family: "Droid Serif", "Lucida Grande", "Lucida Sans Unicode", "DejaVu Sans", Verdana, sans-serif;
font-size: 11pt;
line-height: 1.3;
margin: 40pt;
padding: 0;
} #postamble {
visibility:hidden; /* 隐藏了postamble, 因为总是对不齐, css太菜...... */
text-align: center;
width: 75%;
bottom:0;
margin-left: auto;
margin-right: auto;
_position:absolute;
_top:expression(document.documentElement.clientHeight + document.documentElement.scrollTop - this.offsetHeight);
} .title {
background: url(../images/logo.png) no-repeat 12px 5px; /* 这个图片下载后被我替换了, 本来是org-mode自己的logo */
position: fixed;
display: inline;
left: 0px;
top: 0px;
height: 54px;
width: 100%;
margin-top: 0px;
background-color: #eee;
padding: 0;
z-index: 99;
} #orgquote {
position: fixed;
display: block;
top: 77px;
padding: 5pt;
text-align: center;
background-color: black;
width: 100%;
color: #ccc;
box-shadow: 0px 15px 10px #fff;
font-size: 90%;
font-family: Courier new;
z-index: 98;
} #paypal {
position:fixed;
right: 10px;
top: 15px;
z-index: 100;
} #paypal button {
font-family: Courier new;
cursor: pointer;
color: white;
position:fixed;
display: block;
right: 14px;
top: 15px;
width: 90px;
height: 40px;
box-shadow: 5px 5px 5px #888;
-webkit-box-shadow: 5px 5px 5px #888;
-moz-box-shadow: 5px 5px 5px #888;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
background-color: #53e1e3;
font-weight: bold;
} #paypal button:hover {
position:fixed;
display: block;
right: 9px;
top: 15px;
width: 90px;
height: 40px;
margin-top: 5px;
margin-left: 5px;
box-shadow: 0px 0px 0px #888;
-webkit-box-shadow: 0px 0px 0px #888;
-moz-box-shadow: 0px 0px 0px #888;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
background-color: #49f4f6;
font-weight: bold;
} h1.title {
text-shadow: 2px 2px 4px #999;
padding-top: 23px;
padding-left: 70pt;
font-size: 23pt;
font-family: Courier New;
} #linklist
{
position: fixed;
font-size: 13pt;
font-family: Courier New;
padding-top: 0px;
padding-right: 0px;
top: 107px;
left: 0px;
margin-top: 0px;
width: 180px;
background-color: #fff;
color: black;
box-shadow: 8px 8px 12px #ccc;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-bottomright: 10px;
z-index: 100;
} #linklist a {
color: black;
font-weight: normal;
text-decoration: none;
display:block;
padding: 7pt;
} #linklist ul {
margin: 0;
padding: 0;
} #linklist li {
text-align: right;
margin: 0;
} .timestamp {
font-family: Courier New;
color: #888888;
} #linklist li:hover {
border-left: 7px solid #537d7b;
} pre {
background-color: #eee;
font-family: "Droid Sans Mono";
box-shadow: 5px 5px 5px #888;
border: none;
padding: 5pt;
margin-bottom: 14pt;
color: black;
padding: 12pt;
font-family: Courier New;
font-size: 95%;
overflow: auto;
} #buttons {
position: fixed;
bottom: 10px;
/* right: 20px; */
left: 20px;
z-index: 100;
width: 100px;
} .ok {
-moz-opacity:.2;
opacity: .2;
filter:alpha(opacity=20);
} .ok:hover {
-moz-opacity:1;
opacity: 1;
filter:alpha(opacity=100);
} .outline-2 {
position: relative;
left: 215px;
top: 105px;
width: 75%;
padding-bottom: 5pt;
} #twit {
-moz-opacity:.2;
opacity: .2;
filter:alpha(opacity=20);
position: fixed;
top: 362px;
box-shadow: 8px 8px 12px #ccc;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-bottomright: 10px;
z-index: 100;
} #twit:hover {
-moz-opacity:1;
opacity: 1;
filter:alpha(opacity=100); position: fixed;
top: 362px;
box-shadow: 8px 8px 12px #ccc;
z-index: 100;
} #outline-container-1 {
padding-top: 3pt;
} .outline-2 h2 {
font-family: Courier New;
} .outline-2 h3 {
font-family: Courier New;
} p {
margin-top: 0;
text-align: justify;
} a:link {
font-weight: normal;
text-decoration: none;
/* color: #1c3030; */
/* color: #A34D32; */
} a:visited {
font-weight: normal;
text-decoration: none;
/* color: #5e251e; */
/* color: #6E2432; */
} a:hover, a:active {
text-decoration: underline;
/* color: #3d696a; */
/* color: #537d7b; */
} dd {
text-align: justify;
margin-bottom: 14pt;
} dt {
font-size: 110%;
font-family: Courier New;
color: #1c3030;
/* color: #537d7b; */
padding: 3px;
margin-bottom: 3px;
} li {
margin: 10px;
text-align: justify;
list-style-image : url(../images/triangle.png); /* 这个图片就是每个li 前面的小箭头 */
} #table-of-contents {
font-size: 9pt;
position: fixed;
right: 0em;
top: 0em;
background: white;
-webkit-box-shadow: 0 0 1em #777777;
-moz-box-shadow: 0 0 1em #777777;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomleft: 5px;
text-align: right;
/* ensure doesn't flow off the screen when expanded */
max-height: 80%;
overflow: auto;
z-index: 200;
} #table-of-contents h2 {
font-size: 9pt;
max-width: 8em;
font-weight: normal;
padding-left: 0.5em;
padding-top: 0.05em;
padding-bottom: 0.05em;
} #table-of-contents ul {
margin-left: 14pt;
margin-bottom: 10pt;
padding: 0
} #table-of-contents li {
padding: 0;
margin: 1px;
list-style: none;
} #table-of-contents ul>:first-child {
color: blue;
} #table-of-contents #text-table-of-contents {
display: none;
text-align: left;
} #table-of-contents:hover #text-table-of-contents {
display: block;
padding: 0.5em;
margin-top: -1.5em;
} img.random {
max-width: 750px;
max-height: 380px;
margin-bottom: 10pt;
border: 1px solid black;
} @media screen
{
#table-of-contents {
float: right;
border: 1px solid #CCC;
max-width: 50%;
overflow: auto;
}
} /* END OF @media screen */

: 上面的css中有2个图片是在线的, 我下载后放在 ../images 目录中了

1.4 导出html

最后整个导出工具的目录如下:

.
├── css
│ └── org-manual.css
├── images
│ ├── logo.png
│ └── triangle.png
├── Makefile
└── publish-config.el

把要导出的org文件放到上面配置的 ~/tmp/www 目录中, 然后运行命令 make html 就可以导出html到 目录 ~/tmp/output 中了.

最后附一张这篇文章生成的html截图:

Date: 2014-01-14T16:00+0800

Author: wangyubin

Org version 7.9.3f with Emacs version 24

Validate XHTML 1.0

emacs org-mode文件转html文件的更多相关文章

  1. chmod a+w . 权限控制 su、sudo 修改文件所有者和文件所在组

    对当前目录对所有用户开放读写权限 chmod a+r . $ sudo chmod -R a+w /usr/lib/python2.7 所有用户添加文件的写权限 [linux]su.sudo.sudo ...

  2. chmod a+w . 权限控制 su、sudo 修改文件所有者和文件所在组 添加用户到sudoer列表中 当前用户信息

    对当前目录对所有用户开放读写权限 chmod a+r . $ sudo chmod -R a+w /usr/lib/python2.7 所有用户添加文件的写权限 [linux]su.sudo.sudo ...

  3. UWP开发之Template10实践:本地文件与照相机文件操作的MVVM实例(图文付原代码)

    前面[UWP开发之Mvvmlight实践五:SuspensionManager中断挂起以及复原处理]章节已经提到过Template10,为了认识MvvmLight的区别特做了此实例. 原代码地址:ht ...

  4. 从java文件和CS文件里查询方法使用次数工具

    前几天,领导让我找一下老系统(Java)里getRemoteUser方法都哪个文件用了,package是什么,方法被调用了多少次,当时因为着急,所以,直接人工找的,但是以后要是再出现,人工找就太讨厌了 ...

  5. java中的文件读取和文件写出:如何从一个文件中获取内容以及如何向一个文件中写入内容

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...

  6. C#的Process类调用第三方插件实现PDF文件转SWF文件

    在项目开发过程中,有时会需要用到调用第三方程序实现本系统的某一些功能,例如本文中需要使用到的swftools插件,那么如何在程序中使用这个插件,并且该插件是如何将PDF文件转化为SWF文件的呢?接下来 ...

  7. Excel文件转plist文件出现的文件编码问题

    今天在测试时遇到了需要将大量整理好的Excel数据转换为plist文件的情况.百度了一下教程,发现虽然别人也遇到过类似的情况,但是有些讲的还是不够细致.所以做如下整理.   百度到的内容中有使用Mes ...

  8. 使用java读取文件夹中文件的行数

    使用java统计某文件夹下所有文件的行数 经理突然交代一个任务:要求统计某个文件夹下所有文件的行数.在网上查了一个多小时没有解决.后来心里不爽就决定自己写一个java类用来统计文件的行数,于是花了两个 ...

  9. 【Linux】Linux统计文件夹、文件数量的命令

    # 查看当前目录下的文件数量(不包含子目录中的文件) ls -l|grep "^-"| wc -l # 查看当前目录下的文件数量(包含子目录中的文件) 注意:R,代表子目录 ls ...

  10. python 根据现有文件树创建文件树

    # -*- coding: utf-8 -*- import os, errno def fileName(path):#获取文件夹 str = '' for i in range(1,len(pat ...

随机推荐

  1. Java NIO中的通道Channel(二)分散/聚集 Scatter/Gather

    什么是Scatter/Gather scatter/gather指的在多个缓冲区上实现一个简单的I/O操作,比如从通道中读取数据到多个缓冲区,或从多个缓冲区中写入数据到通道: scatter(分散): ...

  2. salesforce零基础学习(九十)项目中的零碎知识点小总结(三)

    本次的内容其实大部分人都遇到过,也知道解决方案.但是因为没有牢记于心,导致问题再次出现还是花费了一点时间去排查了原因.在此记录下来,好记性不如烂笔头,争取下次发现类似的现象可以直接就知道原因.废话少说 ...

  3. salesforce lightning零基础学习(五) 事件阶段(component events phase)

    上一篇介绍了lightning component events的简单介绍.此篇针对上一篇进行深入,主要讲的内容为component event中的阶段(Phase). 一. 阶段(Phase)的概念 ...

  4. Android中AdapterView/Adapter的深度学习

    BaseAdapter的深度学习 博主工作了几年,也用了几年的ListView等AdapterView控件,但关于Adapter的一些问题并没有深入下去,终于有时间学习总结下关于BaseAdapter ...

  5. git第九节---git命令实战

    1. git 项目创建 mkdir git-command 2.git 配置 git config --list 配置用户名 邮箱 git config user.name 'XXX'  --loca ...

  6. JavaWeb学习 (十一)————Session

    一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...

  7. repository和repertory

    在研究.net core的时候知道了仓储这个概念,并发现两个单词repository和repertory 两者都有仓库,储藏所,储藏的意思,repository还指知识渊博的人,repertory除了 ...

  8. HTML中body与html的关系

    转载自张鑫旭-鑫空间-鑫生活[http://www.zhangxinxu.com] 一.相关基础 一个div块级元素没有主动为其设置宽度和高度,浏览器会为其分配可使用的最大宽度(比如全屏宽度),但是不 ...

  9. 洛谷P3899 [湖南集训]谈笑风生(线段树合并)

    题意 题目链接 Sol 线段树合并板子题,目前我看到两种写法,分别是这样的. 前一种每次需要新建一个节点,空间是\(O(4nlogn)\) 后者不需要新建,空间是\(O(nlogn)\)(面向数据算空 ...

  10. 2018-02-18 Antlr4实现简单语言之条件语句

    本系列之前的文章: Antlr4的分析错误处理 Antlr4实现数学四则运算 Antlr4添加中文变量赋求值,括号,各种问题 Antlr4: 修改语法规则更接近普通BNF格式 Antlr4实现简单语言 ...