update blog
[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 (require 'org)
28 (require 'ox-publish)
29 (require 'htmlize)
30
31 ;; To prevent inline-css when exporting html. will use external css
32 (setq org-html-htmlize-output-type 'css)
33
34 (setq blog-extra-head
35       (concat
36        "<link rel='stylesheet' href='/css/my.css' />\n"
37        "<link rel='stylesheet' href='/css/code.css' />"))
38
39 (setq blog-header
40       (concat
41        "<header id= 'banner'>"
42        "<a class=\"title\"href= '/' >Peng Li</a>"
43        "<nav><ul>"
44        "<li><a href= '/index.html' >About</a></li>"
45        "<li><a href= '/posts/sitemap.html' >Blog</a></li>"
46        "</ul></nav>"
47        "</header>"
48        "<hr>"))
49
50 (setq blog-footer
51       (concat 
52        "<hr />\n"
53        org-html-creator-string))
54
55 (defun blog-setup-project-alist (root-dir &optional output-dir)
56   "Set project alist. `output-dir' is the directory of publish-directory.
57 `root-dir' is the root directory of blog repository."
58   (unless (> (length output-dir) 0)
59     (setq output-dir (concat root-dir "/_site/")))
60   (message "Blog dir is: %s\nOut dir is: %s"
61            (format root-dir)
62            (format output-dir))
63   (setq org-publish-project-alist
64         `(
65           ("blog-pages"
66            :base-directory ,root-dir
67            :base-extension "org"
68            :publishing-directory ,output-dir
69            :recursive nil
70            :publishing-function org-html-publish-to-html
71            
72            ;; html style
73            :htlm-link-home "/"
74            ;; disable home/up div
75            :html-home/up-format ""
76            :html-link-home ""
77            :html-link-up ""
78            ;;
79            :html-head nil
80            :html-head-include-default-style nil
81            :html-head-include-scripts nil
82            :html-head-extra  ,blog-extra-head
83            :html-preamble ,blog-header
84            :html-postamble ,blog-footer
85
86            ;; other generic options
87            :with-toc nil
88            )
89
90           ("blog-posts"
91            :base-directory ,(concat root-dir "/posts")
92            :base-extension "org"
93            :publishing-directory ,(concat output-dir "/posts")
94            :recursive t
95            :publishing-function org-html-publish-to-html
96
97            ;; html style
98            :html-link-home "/"
99            ;; disable Home/Up
100            :html-home/up-format ""
101            :html-link-up ""
102            :html-link-home ""
103            ;; Add css file, preamble and posamble
104            :html-head nil
105            :html-head-include-default-style nil
106            :html-head-include-scripts nil
107            :html-head-extra ,blog-extra-head
108            :html-preamble ,blog-header
109            :html-postamble ,blog-footer
110
111            ;; sitemap
112            :auto-sitemap t
113            :sitemap-filename "sitemap.org"
114            :sitemap-title "Blog"
115            :sitemap-sort-files anti-chronologically
116            :sitemap-date-format "%h %d, %Y"
117            :sitemap-file-entry-format "%d ยป %t"
118
119            ;; other generic options
120            :with-toc nil                ; table of contents
121            )
122           
123           ("blog-css"
124            :base-directory ,(concat root-dir "/css")
125            :base-extension ".*"
126            :publishing-directory ,(concat output-dir "/css")
127            :publishing-function org-publish-attachment
128            :recursive t)
129           ("blog-cgi"
130            :base-directory ,(concat root-dir "/cgi-bin")
131            :base-extension ".*"
132            :publishing-directory ,(concat output-dir "/cgi-bin")
133            :publishing-function org-publish-attachment
134            :recursive t)
135           ("blog" :components ("blog-pages" "blog-posts" "blog-css" "blog-cgi")))))
136
137 (provide 'my-publish)
138 ;;; publish.el ends here