5 (load "~/.emacs.d/lisp/mustache-html.el")
7 (setq org-html-doctype "html5")
8 (setq org-html-head-include-default-style nil)
9 (setq org-html-htmlize-output-type 'css) ; default: 'inline-css
10 (setq org-time-stamp-custom-formats '("%A %e %B %Y" . "%A %e %B %Y at %H:%M"))
11 (setq org-display-custom-times t)
12 (setq my-blog-base-folder "~/websites/stage.vanrenterghem.biz")
13 (setq my-blog-source-folder "~/websites/stage.vanrenterghem.biz/source")
14 (setq my-blog-target-folder "~/websites/stage.vanrenterghem.biz/target")
15 (setq my-blog-target-url "https://www.vanrenterghem.biz/posts/")
16 (setq my-blog-mustache-folder (file-name-concat my-blog-base-folder "html"))
17 (setq my-blog-tags-folder (file-name-concat my-blog-source-folder "tags"))
18 (setq my-blog-posts-folder (file-name-concat my-blog-source-folder "posts"))
20 (setq org-export-time-stamp-file nil)
21 (setq org-rss-use-entry-url-as-guid nil)
23 (defun my-org-get-all-filetags ()
24 "Get list of filetags from all org-files in my-blog-posts-folder."
25 (let ((files (directory-files my-blog-posts-folder t nil nil nil))
27 (save-window-excursion
28 (while (setq x (pop files))
29 (set-buffer (find-file-noselect x))
32 (let ((tagfiles (assoc y tagslist)))
34 (setcdr tagfiles (cons x (cdr tagfiles)))
35 (add-to-list 'tagslist (list y x)))))
36 (my-org-get-filetags)))
39 (defun my-org-get-filetags ()
40 "Get list of filetags for current buffer"
41 (let ((ftags org-file-tags)
45 (org-no-properties x))
48 (defun my-blog-create-tags-files (plist)
49 "Create org files for each tag defined in FILETAGS in posts, storing them in my-blog-tags-folder."
50 (unless (file-directory-p my-blog-tags-folder) (make-directory my-blog-tags-folder))
51 (with-temp-file (file-name-concat my-blog-source-folder "tag-index.org")
52 (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "tags-index.mustache") "\n"))
53 (insert (concat "#+TITLE: Blog - All tags\n"))
54 (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
56 (dolist (tag (sort (my-org-get-all-filetags) (lambda (x y) (string-lessp (car x) (car y))) ))
57 (insert (concat "- [[file:" (file-name-concat my-blog-posts-folder (concat "tag-" (car tag) ".org")) "][" (car tag) "]]\n"))))
58 (dolist (tag (my-org-get-all-filetags))
59 (with-temp-file (file-name-concat my-blog-tags-folder (concat "tag-" (car tag) ".org"))
60 (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "tags.mustache") "\n"))
61 (insert (concat "#+TITLE: " (car tag) "\n"))
62 (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
64 (insert (concat "# " (car tag) "\n\n"))
65 (dolist (tagfile (my-blog-sort-article-list (cdr tag) plist))
66 (let ((relpath (file-relative-name tagfile my-blog-posts-folder)));;not used
67 (message (concat "Processing " tagfile))
68 (insert (concat "- " (format "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry
69 (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date tagfile plist))
71 (org-publish-find-title tagfile plist))
73 ;(my-org-publish-sitemap-default-entry tagfile nil plist) "\n")))))))
75 (defun my-org-publish-sitemap-default-entry (entry style project)
76 "My format for site map ENTRY, as a string.
77 ENTRY is a file name. STYLE is the style of the sitemap.
78 PROJECT is the current project."
79 (cond ((not (directory-name-p entry))
80 (format "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry
81 (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date entry project))
83 (org-publish-find-title entry project)))
85 ;; Return only last subdir.
86 (file-name-nondirectory (directory-file-name entry)))
89 (defun my-blog-parse-sitemap-list (l)
90 "Convert the sitemap list in to a list of filenames."
92 (let ((link (with-temp-buffer
93 (let ((org-inhibit-startup nil))
96 (goto-char (point-min))
97 (org-element-link-parser)))))
99 (plist-get (cadr link) :path))))
102 (defun my-blog-sort-article-list (l p)
103 "sort the article list anti-chronologically."
104 (sort l #'(lambda (a b)
105 (let ((d-a (org-publish-find-date a p))
106 (d-b (org-publish-find-date b p)))
107 (not (time-less-p d-a d-b))))))
109 (defun my-blog-get-preview (file)
110 "Clips a section of a post in FILE to be used as preview in the sitemap.
111 Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the first section between 2 blank lines."
113 (insert-file-contents file)
114 (goto-char (point-min))
115 (let* ((beg (or (re-search-forward "^#\\+BEGIN_PREVIEW$" nil t 1)
116 (re-search-forward "^$")))
117 (end (or (if (re-search-forward "^#\\+END_PREVIEW$" nil t 1)
119 (progn (goto-char (+ 1 beg))
120 (re-search-forward "^$" nil t 2)))))
121 (buffer-substring beg end))))
123 (defun my-blog-sitemap (title list)
124 "Generate the sitemap landing page for my blog."
125 (my-plain-publish-sitemap-default title list) ; Create additional sitemap
127 ;; mangle the parsed list given to us into a plain lisp list of files
128 (let* ((filenames (my-blog-parse-sitemap-list list))
129 (project-plist (assoc "posts" org-publish-project-alist))
130 (articles (my-blog-sort-article-list filenames project-plist)))
131 (dolist (file filenames)
132 (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
133 (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/posts/"))
134 (title (org-publish-find-title file project-plist))
135 (date (format-time-string (cdr org-time-stamp-formats) (org-publish-find-date file project-plist)))
136 (preview (my-blog-get-preview abspath))
138 ;; insert a horizontal line before every post, kill the first one
141 (insert (concat "* [[file:" relpath "][" title "]]\n"))
142 ;; add properties for `ox-rss.el' here
143 (let ((rss-permalink (concat (file-name-sans-extension relpath) ".html"))
146 (org-set-property "RSS_PERMALINK" rss-permalink)
147 (org-set-property "PUBDATE" rss-pubdate)
148 (org-set-property "RSS_TITLE" title))
149 ;; insert the date, preview, & read more link
150 (insert (concat "Published: " date "\n\n"))
152 ;(insert (concat "#+INCLUDE: \"" relpath "\" :only-contents t :lines \"1-10\"\n"))
154 (insert (concat "[[file:" relpath "][Read More...]]\n"))))
155 ;; kill the first hrule to make this look OK
156 (goto-char (point-min))
157 (let ((kill-whole-line t)) (kill-line))
158 ;; insert a title and save
159 (insert "#+OPTIONS: title:nil\n")
160 (insert "#+TITLE: Frederik Vanrenterghem's blog\n")
161 (insert "#+AUTHOR: Frederik Vanrenterghem\n")
162 (insert "#+EMAIL: frederik@vanrenterghem.biz\n")
163 (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
164 (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "post-index.mustache") "\n"))
168 (defun my-plain-publish-sitemap-default (title list)
169 "Create a simple site map, as a string.
170 TITLE is the title of the site map. LIST is an internal
171 representation for the files to include, as returned by
173 (with-temp-file "~/websites/stage.vanrenterghem.biz/source/sitemap.org"
174 (let* ((filenames (my-blog-parse-sitemap-list list))
175 (project-plist (assoc "posts" org-publish-project-alist))
176 (articles (my-blog-sort-article-list filenames project-plist)))
177 (dolist (file filenames)
178 (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
179 (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/"))
180 (title (org-publish-find-title file project-plist))
181 (date (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date file project-plist))))
182 (insert (concat "* " date " - [[file:" relpath "][" title "]]\n"))))
183 (goto-char (point-min))
184 (insert "#+OPTIONS: ^:nil\n")))) ; do not use underscores as subscript
186 (defun my-blog-cleanup-sitemaps (plist)
187 "Clean up temporary files created in the process of publishing"
188 (delete-file (file-name-concat my-blog-source-folder "sitemap.org"))
189 (delete-file (file-name-concat my-blog-posts-folder "sitemap.org"))
190 (delete-file (file-name-concat my-blog-posts-folder "sitemap.org~"))
194 (setq org-publish-project-alist
196 :base-directory ,my-blog-source-folder
197 :base-extension "org"
198 :publishing-directory ,my-blog-target-folder
199 :publishing-function org-mustache-html-publish-to-html
200 :mustache-template ,(file-name-concat my-blog-mustache-folder "landing.mustache")
205 :html-content-class nil
206 :html-head-include-default-style nil
214 :base-directory ,my-blog-posts-folder
215 :base-extension "org"
216 :publishing-directory ,(file-name-concat my-blog-target-folder "posts")
217 :publishing-function org-mustache-html-publish-to-html
218 :mustache-template ,(file-name-concat my-blog-mustache-folder "post.mustache")
219 :preparation-function my-blog-create-tags-files
220 :exclude "html*\\|assets*\\|index.org\\|sitemap.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp
221 :html-content-class nil
225 :sitemap-title "All posts"
226 :html-head-include-default-style nil
233 :sitemap-sort-folders ignore-errors
234 :sitemap-function my-blog-sitemap
235 :sitemap-sort-files anti-chronologically
236 :sitemap-filename "sitemap.org"
240 :base-directory ,(file-name-concat my-blog-source-folder "tags")
241 :base-extension "org"
242 :publishing-directory ,(file-name-concat my-blog-target-folder "posts")
243 :publishing-function org-mustache-html-publish-to-html
244 :mustache-template ,(file-name-concat my-blog-mustache-folder "tags.mustache")
245 :html-content-class nil
249 :html-head-include-default-style nil
259 :base-directory ,(file-name-concat my-blog-source-folder "assets")
262 :publishing-directory ,(file-name-concat my-blog-target-folder "assets")
263 :publishing-function org-publish-attachment
264 :completion-function my-blog-cleanup-sitemaps
268 :base-directory ,my-blog-posts-folder
269 :base-extension "org"
270 :publishing-directory ,(file-name-concat my-blog-target-folder "posts")
271 :publishing-function org-rss-publish-to-rss
273 :title "Frederik Vanrenterghem's blog"
274 :html-link-home ,my-blog-target-url
275 :html-link-use-abs-url t
278 :include ("sitemap.org")
279 :table-of-contents nil
282 ("website" :components ("posts" "rss" "tags" "landing" "assets"))))
284 (org-publish-initialize-cache "website")