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