fix typo
[blog.git] / my-publish.el
1 ;;; my-publish.el --- Publish blog with org-mode        -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2017  Peng Li
4
5 ;; Author: Peng Li <seudut@gmail.com>
6 ;; Keywords: lisp, abbrev
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; Using this emacs script to publish the blog org file 
24
25 ;;; Code:
26
27 ;; (defconst root-dir "~/Private/blog/")
28
29 (require 'org)
30 (require 'ox-publish)
31
32 ;; To prevent inline-css when exporting html. will use external css
33 (setq org-html-htmlize-output-type 'css)
34
35 (setq blog-extra-head
36       (concat
37        ;; "<link rel='stylesheet' href='" css-file "' />\n"
38        "<link rel='stylesheet' href='../css/main.css' />\n"
39        "<link rel='stylesheet' href='../css/code.css' />"
40        ))
41
42 (setq blog-header
43       (concat
44        " <header id= 'banner' > "
45        "<h1><a href= '/' >Peng Li</a></h1>"
46        "<hr>"
47        "<nav><ul>"
48        "<li><a href= '/' >About</a></li>"
49        "<li><a href= '/blog.html' >Blog</a></li>"
50        "<li><a href= '/home.html' >Home</a></li>"
51        "</ul></nav>"
52        "</header>"))
53
54 (setq blog-footer
55       "<hr />\n
56 <p><span style=\"float: left;\"><a href= \"/blog.xml\">RSS</a></span>
57 License: <a href= \"https://creativecommons.org/licenses/by-sa/4.0/\">CC BY-SA 4.0</a></p\n")
58
59 (defun blog-setup-project-alist (root-dir &optional output-dir)
60   "Set project alist. `output-dir' is the directory of publish-directory.
61 `root-dir' is the root directory of blog repository."
62   (unless output-dir (setq output-dir (concat root-dir "_site/")))
63   (setq org-publish-project-alist
64         `(
65           ("blog-pages"
66            ;; publishing
67            :base-directory ,root-dir
68            :base-extension "org"
69            :publishing-directory ,output-dir
70            :recursive nil
71            :publishing-function org-html-publish-to-html
72            
73            ;; html style
74            :htlm-link-home "/"
75            ;; disable home/up div
76            :html-home/up-format ""
77            :html-link-home ""
78            :html-link-up ""
79            ;;
80            :html-head nil
81            :html-head-include-default-style nil
82            :html-head-include-scripts nil
83            :html-head-extra  ,blog-extra-head
84            :html-preamble ,blog-header
85            :html-postamble ,blog-footer)
86
87           ("blog-posts"
88            ;; publishing
89            :base-directory ,(concat root-dir "/posts")
90            :base-extension "org"
91            :publishing-directory ,(concat output-dir "/posts")
92            :recursive t
93            :publishing-function org-html-publish-to-html
94
95            ;; html style
96            :html-link-home "/"
97            ;; disable Home/Up
98            :html-home/up-format ""
99            :html-link-up ""
100            :html-link-home ""
101            ;; Add css file, preamble and posamble
102            :html-head nil
103            :html-head-include-default-style nil
104            :html-head-include-scripts nil
105            :html-head-extra ,blog-extra-head
106            :html-preamble ,blog-header
107            :html-postamble ,blog-footer
108
109            ;; sitemap
110            :auto-sitemap t
111            :sitemap-filename "sitemap.org"
112            :sitemap-title "Sitemap")
113           
114           ("blog-css"
115            :base-directory ,(concat root-dir "/css")
116            :base-extension ".*"
117            :publishing-directory ,(concat output-dir "/css")
118            :publishing-function org-publish-attachment
119            :recursive t)
120           ("blog-cgi"
121            :base-directory ,(concat root-dir "/cgi-bin")
122            :base-extension ".*"
123            :publishing-directory ,(concat output-dir "/cgi-bin")
124            :publishing-function org-publish-attachment
125            :recursive t)
126           ("blog" :components ("blog-pages" "blog-posts" "blog-css" "blog-cgi")))))
127
128
129 (defun blog-publish (out-dir force)
130   "publish the project"
131   (interactive)
132   (blog-setup-project out-dir)
133   (org-publish-project "blog" force))
134
135
136 (provide 'my-publish)
137 ;;; publish.el ends here