move sitemap.org into gitignore
[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 (setq org-publish-project-alist
72       `(
73         ;; ("org-notes"
74         ;;  :base-directory ,root-dir
75         ;;  :base-extension "org"
76         ;;  :publishing-directory ,publish-dir
77         ;;  :recursive t
78         ;;  :publishing-function org-html-publish-to-html
79         ;;  :headline-levels 4
80         ;;  :section-numbers nil
81         ;;  :auto-preamble t
82         ;;  :auto-sitemap t          ;Generate sitmap.org automagicaly...
83         ;;  :sitemap-filename "sitemap.org" ;... call it sitemap.org (it's the default )...
84         ;;  :sitemap-title "Sitemap"
85
86         ;;  :html-table-of-contents nil
87         ;;  :html-postamble nil ;dont export creator auto validation info in html postamble div
88         ;;  :html-link-home "/"
89         ;;  :html-head  ,(concat  "<link rel='stylesheet' href='" css-file  "' />")
90         ;;  :html-head-include-default-style nil
91         ;;  :html-head-include-scripts nil)
92         ("blog-pages"
93          ;; publishing
94          :base-directory ,root-dir
95          :base-extension "org"
96          :publishing-directory ,publish-dir
97          :recursive nil
98          :publishing-function org-html-publish-to-html
99          
100          ;; html style
101          :html-head  ,(concat  "<link rel='stylesheet' href='" css-file  "' />")
102          :html-postamble nil)
103         ("blog-posts"
104          ;; publishing
105          :base-directory ,(concat root-dir "posts")
106          :base-extension "org"
107          :publishing-directory ,(concat publish-dir "posts")
108          :recursive t
109          :publishing-function org-html-publish-to-html
110          :html-link-home "/"
111          
112          ;; html style
113          :html-head ,(concat "<link rel='stylesheet' href='" css-file "' />")
114          ;; don't export creator auto validation info in html postamble div
115          :html-postamble nil)
116         ("blog-css"
117          :base-directory ,(concat root-dir "css")
118          :base-extension ".*"
119          :publishing-directory ,(concat publish-dir "css")
120          :publishing-function org-publish-attachment
121          :recursive t)
122         ("blog-cgi"
123          :base-directory ,(concat root-dir "cgi-bin")
124          :base-extension ".*"
125          :publishing-directory ,(concat publish-dir "cgi-bin")
126          :publishing-function org-publish-attachment
127          :recursive t)
128         ("blog" :components ("blog-pages" "blog-posts" "blog-css" "blog-cgi"))))
129
130 (org-publish-project "blog" force-publish)
131
132 ;; (provide 'blog)
133 (kill-emacs 0)
134 ;;; blog.el ends here