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