f6944334aa419fdcd70f6c352de79c56457908a5
[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 ;;        "<span><a href= \"http://orgmode.org\"/>Org-mode </a>" (org-version) "</span>"))
57 (setq blog-footer
58       (concat 
59        "<hr />\n"
60        org-html-creator-string))
61
62 (defun blog-setup-project-alist (root-dir &optional output-dir)
63   "Set project alist. `output-dir' is the directory of publish-directory.
64 `root-dir' is the root directory of blog repository."
65   (unless (> (length output-dir) 0)
66     (setq output-dir (concat root-dir "/_site/")))
67   (message "Blog dir is: %s\nOut dir is: %s"
68            (format root-dir)
69            (format output-dir))
70   (setq org-publish-project-alist
71         `(
72           ("blog-pages"
73            :base-directory ,root-dir
74            :base-extension "org"
75            :publishing-directory ,output-dir
76            :recursive nil
77            :publishing-function org-html-publish-to-html
78            
79            ;; html style
80            :htlm-link-home "/"
81            ;; disable home/up div
82            :html-home/up-format ""
83            :html-link-home ""
84            :html-link-up ""
85            ;;
86            :html-head nil
87            :html-head-include-default-style nil
88            :html-head-include-scripts nil
89            :html-head-extra  ,blog-extra-head
90            :html-preamble ,blog-header
91            :html-postamble ,blog-footer
92
93            ;; other generic options
94            :with-toc nil
95            )
96
97           ("blog-posts"
98            :base-directory ,(concat root-dir "/posts")
99            :base-extension "org"
100            :publishing-directory ,(concat output-dir "/posts")
101            :recursive t
102            :publishing-function org-html-publish-to-html
103
104            ;; html style
105            :html-link-home "/"
106            ;; disable Home/Up
107            :html-home/up-format ""
108            :html-link-up ""
109            :html-link-home ""
110            ;; Add css file, preamble and posamble
111            :html-head nil
112            :html-head-include-default-style nil
113            :html-head-include-scripts nil
114            :html-head-extra ,blog-extra-head
115            :html-preamble ,blog-header
116            :html-postamble ,blog-footer
117
118            ;; sitemap
119            :auto-sitemap t
120            :sitemap-filename "sitemap.org"
121            :sitemap-title "Sitemap"
122
123            ;; other generic options
124            :with-toc nil                ; table of contents
125            )
126           
127           ("blog-css"
128            :base-directory ,(concat root-dir "/css")
129            :base-extension ".*"
130            :publishing-directory ,(concat output-dir "/css")
131            :publishing-function org-publish-attachment
132            :recursive t)
133           ("blog-cgi"
134            :base-directory ,(concat root-dir "/cgi-bin")
135            :base-extension ".*"
136            :publishing-directory ,(concat output-dir "/cgi-bin")
137            :publishing-function org-publish-attachment
138            :recursive t)
139           ("blog" :components ("blog-pages" "blog-posts" "blog-css" "blog-cgi")))))
140
141 (provide 'my-publish)
142 ;;; publish.el ends here