3 (load "~/.emacs.d/lisp/mustache-html.el")
5 (setq org-html-doctype "html5")
6 (setq org-html-head-include-default-style nil)
7 (setq org-html-htmlize-output-type 'css) ; default: 'inline-css
8 (setq org-time-stamp-custom-formats '("%A %e %B %Y" . "%A %e %B %Y at %H:%M"))
9 (setq org-display-custom-times t)
10 (setq my-blog-base-folder "~/websites/stage.vanrenterghem.biz")
11 (setq my-blog-source-folder "~/websites/stage.vanrenterghem.biz/source")
12 (setq my-blog-target-folder "~/websites/stage.vanrenterghem.biz/target")
13 (setq my-blog-mustache-folder (file-name-concat my-blog-base-folder "html"))
14 (setq my-blog-tags-folder (file-name-concat my-blog-source-folder "tags"))
15 (setq my-blog-posts-folder (file-name-concat my-blog-source-folder "posts"))
17 (setq org-export-time-stamp-file nil)
18 (setq org-rss-use-entry-url-as-guid nil)
20 (defun my-org-get-all-filetags ()
21 "Get list of filetags from all org-files in my-blog-posts-folder."
22 (let ((files (directory-files my-blog-posts-folder t nil nil nil))
24 (save-window-excursion
25 (while (setq x (pop files))
26 (set-buffer (find-file-noselect x))
29 (let ((tagfiles (assoc y tagslist)))
31 (setcdr tagfiles (cons x (cdr tagfiles)))
32 (add-to-list 'tagslist (list y x)))))
33 (my-org-get-filetags)))
36 (defun my-org-get-filetags ()
37 "Get list of filetags for current buffer"
38 (let ((ftags org-file-tags)
42 (org-no-properties x))
45 (defun my-blog-create-tags-files (plist)
46 "Create org files for each tag defined in FILETAGS in posts, storing them in my-blog-tags-folder."
47 (unless (file-directory-p my-blog-tags-folder) (make-directory my-blog-tags-folder))
48 (with-temp-file (file-name-concat my-blog-source-folder "tag-index.org")
49 (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "tags-index.mustache") "\n"))
50 (insert (concat "#+TITLE: Blog - All tags\n"))
51 (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
53 (dolist (tag (sort (my-org-get-all-filetags) (lambda (x y) (string-lessp (car x) (car y))) ))
54 (insert (concat "- [[file:" (file-name-concat my-blog-posts-folder (concat "tag-" (car tag) ".org")) "][" (car tag) "]]\n"))))
55 (dolist (tag (my-org-get-all-filetags))
56 (with-temp-file (file-name-concat my-blog-tags-folder (concat "tag-" (car tag) ".org"))
57 (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "tags.mustache") "\n"))
58 (insert (concat "#+TITLE: " (car tag) "\n"))
59 (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
61 (insert (concat "# " (car tag) "\n\n"))
62 (dolist (tagfile (my-blog-sort-article-list (cdr tag) plist))
63 (let ((relpath (file-relative-name tagfile my-blog-posts-folder)));;not used
64 (message (concat "Processing " tagfile))
65 (insert (concat "- " (format "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry
66 (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date tagfile plist))
68 (org-publish-find-title tagfile plist))
70 ;(my-org-publish-sitemap-default-entry tagfile nil plist) "\n")))))))
72 (defun my-org-publish-sitemap-default-entry (entry style project)
73 "My format for site map ENTRY, as a string.
74 ENTRY is a file name. STYLE is the style of the sitemap.
75 PROJECT is the current project."
76 (cond ((not (directory-name-p entry))
77 (format "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry
78 (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date entry project))
80 (org-publish-find-title entry project)))
82 ;; Return only last subdir.
83 (file-name-nondirectory (directory-file-name entry)))
86 (defun my-blog-parse-sitemap-list (l)
87 "Convert the sitemap list in to a list of filenames."
89 (let ((link (with-temp-buffer
90 (let ((org-inhibit-startup nil))
93 (goto-char (point-min))
94 (org-element-link-parser)))))
96 (plist-get (cadr link) :path))))
99 (defun my-blog-sort-article-list (l p)
100 "sort the article list anti-chronologically."
101 (sort l #'(lambda (a b)
102 (let ((d-a (org-publish-find-date a p))
103 (d-b (org-publish-find-date b p)))
104 (not (time-less-p d-a d-b))))))
106 (defun my-blog-get-preview (file)
107 "Clips a section of a post in FILE to be used as preview in the sitemap.
108 Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the first section between 2 blank lines."
110 (insert-file-contents file)
111 (goto-char (point-min))
112 (let* ((beg (or (re-search-forward "^#\\+BEGIN_PREVIEW$" nil t 1)
113 (re-search-forward "^$")))
114 (end (or (if (re-search-forward "^#\\+END_PREVIEW$" nil t 1)
116 (progn (goto-char (+ 1 beg))
117 (re-search-forward "^$" nil t 2)))))
118 (buffer-substring beg end))))
120 (defun my-blog-sitemap (title list)
121 "Generate the sitemap landing page for my blog."
122 (my-plain-publish-sitemap-default title list) ; Create additional sitemap
123 (my-blog-publish-rss-sitemap title list) ; Create RSS sitemap
125 ;; mangle the parsed list given to us into a plain lisp list of files
126 (let* ((filenames (my-blog-parse-sitemap-list list))
127 (project-plist (assoc "posts" org-publish-project-alist))
128 (articles (my-blog-sort-article-list filenames project-plist)))
129 (dolist (file filenames)
130 (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
131 (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/posts/"))
132 (title (org-publish-find-title file project-plist))
133 (date (format-time-string (cdr org-time-stamp-custom-formats) (org-publish-find-date file project-plist)))
134 (preview (my-blog-get-preview abspath))
136 ;; insert a horizontal line before every post, kill the first one
139 (insert (concat "* [[file:" relpath "][" title "]]\n"))
140 ;; add properties for `ox-rss.el' here
141 ;(let ((rss-permalink (concat (file-name-sans-extension relpath) ".html"))
142 ; (rss-pubdate date))
143 ; (org-set-property "RSS_PERMALINK" rss-permalink)
144 ; (org-set-property "PUBDATE" rss-pubdate))
145 ;; insert the date, preview, & read more link
146 (insert (concat "Published: " date "\n\n"))
148 ;(insert (concat "#+INCLUDE: \"" relpath "\" :only-contents t :lines \"1-10\"\n"))
150 (insert (concat "[[file:" relpath "][Read More...]]\n"))))
151 ;; kill the first hrule to make this look OK
152 (goto-char (point-min))
153 (let ((kill-whole-line t)) (kill-line))
154 ;; insert a title and save
155 (insert "#+OPTIONS: title:nil\n")
156 (insert "#+TITLE: Blog\n")
157 (insert "#+AUTHOR: Frederik Vanrenterghem\n")
158 (insert "#+EMAIL: frederik@vanrenterghem.biz\n")
159 (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
160 (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "post-index.mustache") "\n"))
164 (defun my-plain-publish-sitemap-default (title list)
165 "Create a simple site map, as a string.
166 TITLE is the title of the site map. LIST is an internal
167 representation for the files to include, as returned by
169 (with-temp-file "~/websites/stage.vanrenterghem.biz/source/sitemap.org"
170 (let* ((filenames (my-blog-parse-sitemap-list list))
171 (project-plist (assoc "posts" org-publish-project-alist))
172 (articles (my-blog-sort-article-list filenames project-plist)))
173 (dolist (file filenames)
174 (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
175 (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/"))
176 (title (org-publish-find-title file project-plist))
177 (date (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date file project-plist))))
178 (insert (concat "* " date " - [[file:" relpath "][" title "]]\n"))))
179 (goto-char (point-min))
180 (insert "#+OPTIONS: ^:nil\n")))) ; do not use underscores as subscript
182 (defun my-blog-publish-rss-sitemap (title list)
183 "Create a simple site map, as a string.
184 TITLE is the title of the site map. LIST is an internal
185 representation for the files to include, as returned by
188 (message "Creating RSS index.")
190 (let* ((filenames (my-blog-parse-sitemap-list list))
191 (project-plist (assoc "posts" org-publish-project-alist))
192 ;;(articles (my-blog-sort-article-list filenames project-plist))
194 (insert "#+AUTHOR: Frederik Vanrenterghem\n")
195 (dolist (file filenames)
196 (unless (eq (file-name-base file) "rss.org")
197 (message "Processing %s for RSS index." file)
198 (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
199 (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/"))
200 (title (org-publish-find-title file project-plist))
201 (date (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date file project-plist)))
202 (rss-permalink (file-name-sans-extension relpath))
203 (preview (my-blog-get-preview abspath)))
204 (insert (concat "* [[file:" relpath "][" title "]]"))
205 (org-set-property "RSS_PERMALINK" rss-permalink)
206 (org-set-property "PUBDATE" date)
207 (org-set-property "RSS_TITLE" title)
210 (goto-char (point-min))
211 (insert "#+OPTIONS: ^:nil\n"))
212 (write-file "~/websites/stage.vanrenterghem.biz/source/posts/rss.org")))
215 (defun my-blog-cleanup-sitemaps (plist)
216 "Clean up temporary files created in the process of publishing"
217 (delete-file (file-name-concat my-blog-source-folder "sitemap.org"))
218 (delete-file (file-name-concat my-blog-posts-folder "sitemap.org"))
221 (setq org-publish-project-alist
223 :base-directory ,my-blog-source-folder
224 :base-extension "org"
225 :publishing-directory ,my-blog-target-folder
226 :publishing-function org-mustache-html-publish-to-html
227 :mustache-template ,(file-name-concat my-blog-mustache-folder "landing.mustache")
232 :html-content-class nil
233 :html-head-include-default-style nil
241 :base-directory ,my-blog-posts-folder
242 :base-extension "org"
243 :publishing-directory ,(file-name-concat my-blog-target-folder "posts")
244 :publishing-function org-mustache-html-publish-to-html
245 :mustache-template ,(file-name-concat my-blog-mustache-folder "post.mustache")
246 :preparation-function my-blog-create-tags-files
247 :exclude "html*\\|assets*\\|index.org\\|rss.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp
248 :html-content-class nil
252 :sitemap-title "All posts"
253 :html-head-include-default-style nil
260 :sitemap-sort-folders ignore-errors
261 :sitemap-function my-blog-sitemap
262 :sitemap-sort-files anti-chronologically
263 :sitemap-filename "sitemap.org"
267 :base-directory ,(file-name-concat my-blog-source-folder "tags")
268 :base-extension "org"
269 :publishing-directory ,(file-name-concat my-blog-target-folder "posts")
270 :publishing-function org-mustache-html-publish-to-html
271 :mustache-template ,(file-name-concat my-blog-mustache-folder "tags.mustache")
272 :html-content-class nil
276 :html-head-include-default-style nil
286 :base-directory ,(file-name-concat my-blog-source-folder "assets")
289 :publishing-directory ,(file-name-concat my-blog-target-folder "assets")
290 :publishing-function org-publish-attachment
291 :completion-function my-blog-cleanup-sitemaps
295 :base-directory ,my-blog-posts-folder
296 :base-extension "org"
297 :publishing-directory ,my-blog-target-folder
298 :publishing-function org-rss-publish-to-rss
301 :html-link-home "https://www.vanrenterghem.biz/"
302 :html-link-use-abs-url t
304 :title "Frederik Vanrenterghem"
305 :rss-image-url "https://test/img/feed-icon-28x28.png"
306 ;:my-rss-stylesheet "/res/rss.xsl" ; custom style sheet
307 ;:completion-function my-website-rss-postprocessor
311 :table-of-contents nil)
313 ("website" :components ("posts" "rss" "tags" "landing" "assets"))))
315 (org-publish-initialize-cache "website")