f9e0da0b45aa20097ba19c334b9b350a0c89e911
[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= '/about.html' >About</a></li>"
45        "<li><a href= '/posts/sitemap.html' >Blog</a></li>"
46        "<li><a href= '/index.html' >Home</a></li>"
47        "</ul></nav>"
48        "</header>"
49        "<hr>"))
50
51 (setq blog-footer
52       (concat 
53        "<hr />\n"
54        org-html-creator-string))
55
56 (defun blog-setup-project-alist (root-dir &optional output-dir)
57   "Set project alist. `output-dir' is the directory of publish-directory.
58 `root-dir' is the root directory of blog repository."
59   (unless (> (length output-dir) 0)
60     (setq output-dir (concat root-dir "/_site/")))
61   (message "Blog dir is: %s\nOut dir is: %s"
62            (format root-dir)
63            (format output-dir))
64   (setq org-publish-project-alist
65         `(
66           ("blog-pages"
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            ;; other generic options
88            :with-toc nil
89            )
90
91           ("blog-posts"
92            :base-directory ,(concat root-dir "/posts")
93            :base-extension "org"
94            :publishing-directory ,(concat output-dir "/posts")
95            :recursive t
96            :publishing-function org-html-publish-to-html
97
98            ;; html style
99            :html-link-home "/"
100            ;; disable Home/Up
101            :html-home/up-format ""
102            :html-link-up ""
103            :html-link-home ""
104            ;; Add css file, preamble and posamble
105            :html-head nil
106            :html-head-include-default-style nil
107            :html-head-include-scripts nil
108            :html-head-extra ,blog-extra-head
109            :html-preamble ,blog-header
110            :html-postamble ,blog-footer
111
112            ;; sitemap
113            :auto-sitemap t
114            :sitemap-filename "sitemap.org"
115            :sitemap-title "Sitemap"
116
117            ;; other generic options
118            :with-toc nil                ; table of contents
119            )
120           
121           ("blog-css"
122            :base-directory ,(concat root-dir "/css")
123            :base-extension ".*"
124            :publishing-directory ,(concat output-dir "/css")
125            :publishing-function org-publish-attachment
126            :recursive t)
127           ("blog-cgi"
128            :base-directory ,(concat root-dir "/cgi-bin")
129            :base-extension ".*"
130            :publishing-directory ,(concat output-dir "/cgi-bin")
131            :publishing-function org-publish-attachment
132            :recursive t)
133           ("blog" :components ("blog-pages" "blog-posts" "blog-css" "blog-cgi")))))
134
135 (provide 'my-publish)
136 ;;; publish.el ends here