-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.el
127 lines (105 loc) · 4.52 KB
/
project.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
(require 'ox-publish)
(require 'cl)
(unless (package-installed-p 'htmlize)
(package-refresh-contents)
(package-install 'htmlize))
(setq make-backup-files nil)
;; Utility function
(defun joh/get-string-from-file (path)
"Return PATH's file content as string."
(with-temp-buffer
(insert-file-contents path)
(buffer-string)))
(setq joh/website/base-dir (concat default-directory "org/"))
(setq joh/website/static-dir (concat default-directory "static/"))
(setq joh/website/publish-dir (concat default-directory "public_html/")) ;; TODO fix the absolute path stuff
(setq joh/website/template-dir (concat default-directory "templates/"))
(defun joh/export-block (export-block contents info)
"If the export block type is gpx, then put the html block
inside a script tag, and insert below a map"
(if (string= (org-element-property :type export-block) "GPX")
(format (joh/get-string-from-file (concat joh/website/template-dir "map.html"))
(org-remove-indentation (org-element-property :value export-block)))
;; If not gpx then delegate to the default html export
(org-html-export-block export-block contents info)))
(org-export-define-derived-backend 'joh/html 'html
:translate-alist '((export-block . joh/export-block)))
(defun joh/publish-to-html (plist filename pub-dir)
"Modified version of org-html-publish-to-html. "
(org-publish-org-to 'joh/html filename
(concat "." (or (plist-get plist :html-extension)
org-html-extension
"html"))
plist pub-dir))
;; Resolve the subdirectory broken links problem
(setq *joh/publish-draft-p* nil)
(defun joh/level-to-path (level)
"Return the right number of .. for the given LEVEL"
(if (= level 0)
""
(concat "../" (joh/level-to-path (- level 1)))))
(defun joh/count-occurences (string char)
"Count the number of occurences of CHAR in the given STRING. "
(loop for c across string when (equal c char) sum 1))
(defun joh/org-pages-subproject (dirname &rest extra-options)
"Return the right project alist to make a subproject of
org-pages.
DIRNAME must end with a slash, unless it represents
the main directory ; it must then be an empty string. "
(let* ((level (joh/count-occurences dirname ?/))
(prefix (joh/level-to-path level))
(pretty-name (if (= 0 (length dirname))
"org-pages"
(concat "org-pages-" (substring dirname 0 -1)))))
`(,pretty-name
:base-directory ,(concat joh/website/base-dir dirname)
:base-extension "org"
,@(if *joh/publish-draft-p* nil '(:exclude "^_"))
:publishing-directory ,(concat joh/website/publish-dir dirname)
:publishing-function joh/publish-to-html
:html-doctype "html5"
:html-head ,(format (joh/get-string-from-file (concat joh/website/template-dir "head.html"))
prefix)
:html-preamble ,(format (joh/get-string-from-file (concat joh/website/template-dir "preamble.html"))
prefix prefix prefix prefix)
:html-postamble ,(joh/get-string-from-file (concat joh/website/template-dir "postamble.html"))
:with-toc nil
:section-numbers nil
,@extra-options)))
(defun joh/org-publish-sitemap (title list)
"Default site map, as a string.
TITLE is the title of the site map. LIST is an internal
representation for the files to include, as returned by
`org-list-to-lisp'. PROJECT is the current project."
(concat "#+TITLE: " title "\n\n"
"#+HTML: <div id=\"sitemap\">\n"
(org-list-to-org list)
"\n#+HTML: </div>"))
(defun joh/org-publish-sitemap-entry (entry style project)
"Modified format for site map ENTRY, as a string.
ENTRY is a file name. STYLE is the style of the sitemap.
PROJECT is the current project."
(cond ((not (directory-name-p entry))
(format "[[file:%s][%s]] :: %s"
;;"[[file:%s][%s]]"
entry
(org-publish-find-title entry project)
(org-publish-find-property entry :description project 'html)))
((eq style 'tree)
;; Return only last subdir.
(file-name-nondirectory (directory-file-name entry)))
(t entry)))
(setq org-publish-project-alist
`(,(joh/org-pages-subproject "")
,(joh/org-pages-subproject "blog/"
:auto-sitemap t
:sitemap-title "All posts"
:sitemap-filename "posts.org"
:sitemap-function #'joh/org-publish-sitemap
:sitemap-format-entry #'joh/org-publish-sitemap-entry)
("org-static"
:base-directory ,joh/website/static-dir
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
:publishing-directory ,joh/website/publish-dir
:recursive t
:publishing-function org-publish-attachment)))