fix title preamble
[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/worg.css' />\n"
39        "<link rel='stylesheet' href='../css/my.css' />\n"
40        "<link rel='stylesheet' href='../css/code.css' />"))
41
42 (setq blog-header
43       (concat
44        "<header id= 'banner'>"
45        "<a class=\"title\"href= '/' >Peng Li</a>"
46        "<nav><ul>"
47        "<li><a href= '/about.html' >About</a></li>"
48        "<li><a href= '/posts/sitemap.html' >Blog</a></li>"
49        "<li><a href= '/index.html' >Home</a></li>"
50        "</ul></nav>"
51        "</header>"
52        "<hr>"))
53
54 (setq blog-footer
55       (concat 
56        "<hr />\n"
57        "<p><span style=\"float: left;\"><a href= \"http://orgmode.org\"/>Org-mode </a>" (org-version) "</span>"))
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 (> (length output-dir) 0)
63     (setq output-dir (concat root-dir "/_site/")))
64   (message "Blog dir is: %s\nOut dir is: %s"
65            (format root-dir)
66            (format output-dir))
67   (setq org-publish-project-alist
68         `(
69           ("blog-pages"
70            :base-directory ,root-dir
71            :base-extension "org"
72            :publishing-directory ,output-dir
73            :recursive nil
74            :publishing-function org-html-publish-to-html
75            
76            ;; html style
77            :htlm-link-home "/"
78            ;; disable home/up div
79            :html-home/up-format ""
80            :html-link-home ""
81            :html-link-up ""
82            ;;
83            :html-head nil
84            :html-head-include-default-style nil
85            :html-head-include-scripts nil
86            :html-head-extra  ,blog-extra-head
87            :html-preamble ,blog-header
88            :html-postamble ,blog-footer
89
90            ;; other generic options
91            :with-toc nil
92            )
93
94           ("blog-posts"
95            :base-directory ,(concat root-dir "/posts")
96            :base-extension "org"
97            :publishing-directory ,(concat output-dir "/posts")
98            :recursive t
99            :publishing-function org-html-publish-to-html
100
101            ;; html style
102            :html-link-home "/"
103            ;; disable Home/Up
104            :html-home/up-format ""
105            :html-link-up ""
106            :html-link-home ""
107            ;; Add css file, preamble and posamble
108            :html-head nil
109            :html-head-include-default-style nil
110            :html-head-include-scripts nil
111            :html-head-extra ,blog-extra-head
112            :html-preamble ,blog-header
113            :html-postamble ,blog-footer
114
115            ;; sitemap
116            :auto-sitemap t
117            :sitemap-filename "sitemap.org"
118            :sitemap-title "Sitemap"
119
120            ;; other generic options
121            :with-toc nil                ; table of contents
122            )
123           
124           ("blog-css"
125            :base-directory ,(concat root-dir "/css")
126            :base-extension ".*"
127            :publishing-directory ,(concat output-dir "/css")
128            :publishing-function org-publish-attachment
129            :recursive t)
130           ("blog-cgi"
131            :base-directory ,(concat root-dir "/cgi-bin")
132            :base-extension ".*"
133            :publishing-directory ,(concat output-dir "/cgi-bin")
134            :publishing-function org-publish-attachment
135            :recursive t)
136           ("blog" :components ("blog-pages" "blog-posts" "blog-css" "blog-cgi")))))
137
138 (provide 'my-publish)
139 ;;; publish.el ends here