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