Add footer
[blog.git] / blog.el
1 ;;; blog.el --- Config file used to export blog      -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2017  Peng Li
4
5 ;; Author: Peng Li <seudut@gmail.com>
6 ;; Keywords: lisp
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 ;; This is emacs config used to export Blog Org files in batch mode.
24
25 ;;; Code:
26
27 (require 'package)
28 (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
29 (package-initialize)
30
31 (setq debug-on-error t)
32
33 ;; package initialise
34 (unless (package-installed-p 'htmlize)
35   (package-refresh-contents)
36   (package-install 'htmlize))
37
38
39 ;; constants
40 ;; (defconst root-dir "~/Private/blog/")
41 (defconst root-dir (file-name-directory (or load-file-name buffer-file-name)))
42 (defvar publish-dir (concat root-dir "_site/"))
43 (defconst css-file "../css/worg.css")
44 (defvar force-publish nil)
45 ;; (defconst css-file (concat root-dir "css/worg.css"))
46
47 (let ((aa (pop command-line-args-left)))
48   (if (>  (length aa) 0)
49       (setq publish-dir aa)))
50
51
52 (let ((force (pop command-line-args-left)))
53   (if (string= force "true")
54       (setq force-publish t)))
55
56
57 ;; (setq publish-dir (or (pop command-line-args-left) publish-dir))
58 (message publish-dir)
59
60 (require 'org)
61 (require 'ox-publish)
62 (require 'htmlize)
63
64 (message "Org-mode version %s" (org-version))
65 (message "publish directory is %s" publish-dir)
66 (message "force %s" force-publish)
67
68 ;; To prevent inline-css when exporting html. will use external css
69 (setq org-html-htmlize-output-type 'css)
70
71
72 (setq blog-extra-head
73       (concat
74        ;; "<link rel='stylesheet' href='" css-file "' />\n"
75        "<link rel='stylesheet' href='../css/main.css' />\n"
76        "<link rel='stylesheet' href='../css/code.css' />"
77        ))
78
79 (setq blog-header
80       (concat
81        " <header id= 'banner' > "
82        "<h1><a href= '/' >Peng Li</a></h1>"
83        "<hr>"
84        "<nav><ul>"
85        "<li><a href= '/' >About</a></li>"
86        "<li><a href= '/blog.html' >Blog</a></li>"
87        "<li><a href= '/home.html' >Home</a></li>"
88        "</ul></nav>"
89        "</header>"))
90
91
92
93 (setq blog-footer
94       "<hr />\n
95 <p><span style=\"float: left;\"><a href= \"/blog.xml\">RSS</a></span>
96 License: <a href= \"https://creativecommons.org/licenses/by-sa/4.0/\">CC BY-SA 4.0</a></p>\n
97 <p><a href= \"/contact.html\"> Contact</a></p>\n")
98
99 ;; don't know why setting this null in `org-publish-project-alist' doesn't work
100 ;; (setf org-html-home/up-format "")
101
102 (setq org-publish-project-alist
103       `(
104         ("blog-pages"
105          ;; publishing
106          :base-directory ,root-dir
107          :base-extension "org"
108          :publishing-directory ,publish-dir
109          :recursive nil
110          :publishing-function org-html-publish-to-html
111          
112          ;; html style
113          :htlm-link-home "/"
114          ;; disable home/up div
115          :html-home/up-format ""
116          :html-link-home ""
117          :html-link-up ""
118          
119          :html-head  ,blog-extra-head
120          :html-postamble nil)
121
122         ("blog-posts"
123          ;; publishing
124          :base-directory ,(concat root-dir "/posts")
125          :base-extension "org"
126          :publishing-directory ,(concat publish-dir "/posts")
127          :recursive t
128          :publishing-function org-html-publish-to-html
129
130          ;; html style
131          :html-link-home "/"
132          ;; disable Home/Up
133          :html-home/up-format ""
134          :html-link-up ""
135          :html-link-home ""
136          ;; Add css file, preamble and posamble
137          :html-head nil
138          :html-head-include-default-style nil
139          :html-head-include-scripts nil
140          :html-head-extra ,blog-extra-head
141          :html-preamble ,blog-header
142          :html-postamble ,blog-footer
143
144          ;; sitemap
145          :auto-sitemap t
146          :sitemap-filename "sitemap.org"
147          :sitemap-title "Sitemap"
148          )
149         
150         ("blog-css"
151          :base-directory ,(concat root-dir "/css")
152          :base-extension ".*"
153          :publishing-directory ,(concat publish-dir "/css")
154          :publishing-function org-publish-attachment
155          :recursive t)
156         ("blog-cgi"
157          :base-directory ,(concat root-dir "/cgi-bin")
158          :base-extension ".*"
159          :publishing-directory ,(concat publish-dir "/cgi-bin")
160          :publishing-function org-publish-attachment
161          :recursive t)
162         ("blog" :components ("blog-pages" "blog-posts" "blog-css" "blog-cgi"))))
163
164 (org-publish-project "blog" force-publish)
165
166 ;; (provide 'blog)
167 (kill-emacs 0)
168 ;;; blog.el ends here