3 (setq org-html-doctype "html5")
4 (setq org-html-head-include-default-style nil)
5 ;(setq org-html-htmlize-output-type 'css) ; default: 'inline-css
8 (defun my-org-publish-sitemap-default-entry (entry style project)
9 "My format for site map ENTRY, as a string.
10 ENTRY is a file name. STYLE is the style of the sitemap.
11 PROJECT is the current project."
12 (cond ((not (directory-name-p entry))
13 (format "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry
14 (format-time-string "%e %b %Y" (org-publish-find-date entry project))
16 (org-publish-find-title entry project)))
18 ;; Return only last subdir.
19 (file-name-nondirectory (directory-file-name entry)))
22 (defun my-blog-parse-sitemap-list (l)
23 "Convert the sitemap list in to a list of filenames."
25 (let ((link (with-temp-buffer
26 (let ((org-inhibit-startup nil))
29 (goto-char (point-min))
30 (org-element-link-parser)))))
32 (plist-get (cadr link) :path))))
35 (defun my-blog-sort-article-list (l p)
36 "sort the article list anti-chronologically."
37 (sort l #'(lambda (a b)
38 (let ((d-a (org-publish-find-date a p))
39 (d-b (org-publish-find-date b p)))
40 (not (time-less-p d-a d-b))))))
42 (defun my-blog-get-preview (file)
43 "Clips a section of a post in FILE to be used as preview in the sitemap.
44 Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the first section between 2 blank lines."
46 (insert-file-contents file)
47 (goto-char (point-min))
48 (let* ((beg (or (re-search-forward "^#\\+BEGIN_PREVIEW$" nil t 1)
49 (re-search-forward "^$")))
50 (end (or (if (re-search-forward "^#\\+END_PREVIEW$" nil t 1)
52 (progn (goto-char (+ 1 beg))
53 (re-search-forward "^$" nil t 2)))))
54 (buffer-substring beg end))))
56 (defun my-blog-sitemap (title list)
57 "Generate the sitemap landing page for my blog."
58 (my-plain-publish-sitemap-default title list)
60 ;; mangle the parsed list given to us into a plain lisp list of files
61 (let* ((filenames (my-blog-parse-sitemap-list list))
62 (project-plist (assoc "posts" org-publish-project-alist))
63 (articles (my-blog-sort-article-list filenames project-plist)))
64 (dolist (file filenames)
65 (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
66 (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/"))
67 (title (org-publish-find-title file project-plist))
68 (date (format-time-string (car org-time-stamp-formats) (org-publish-find-date file project-plist)))
69 (preview (my-blog-get-preview abspath))
71 ;; insert a horizontal line before every post, kill the first one
74 (insert (concat "* [[file:" relpath "][" title "]]\n"))
75 ;; add properties for `ox-rss.el' here
76 ;(let ((rss-permalink (concat (file-name-sans-extension relpath) ".html"))
78 ; (org-set-property "RSS_PERMALINK" rss-permalink)
79 ; (org-set-property "PUBDATE" rss-pubdate))
80 ;; insert the date, preview, & read more link
81 (insert (concat "Published: " date "\n\n"))
83 ;(insert (concat "#+INCLUDE: \"" relpath "\" :only-contents t :lines \"1-10\"\n"))
85 (insert (concat "[[file:" relpath "][Read More...]]\n"))))
86 ;; kill the first hrule to make this look OK
87 (goto-char (point-min))
88 (let ((kill-whole-line t)) (kill-line))
89 ;; insert a title and save
90 (insert "#+OPTIONS: title:nil\n")
91 (insert "#+TITLE: Blog\n")
92 (insert "#+AUTHOR: Frederik Vanrenterghem\n")
93 (insert "#+EMAIL: frederik@vanrenterghem.biz\n")
94 (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
95 (insert "#+mustache-template: ~/websites/stage.vanrenterghem.biz/html/post-index.mustache\n")
99 (defun my-plain-publish-sitemap-default (title list)
100 "Default site map, as a string.
101 TITLE is the title of the site map. LIST is an internal
102 representation for the files to include, as returned by
103 `org-list-to-lisp'. PROJECT is the current project."
104 (with-temp-file "~/websites/stage.vanrenterghem.biz/source/sitemap.org"
105 (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
106 (insert (concat "#+TITLE: " title "\n\n"))
107 (insert (org-list-to-org list))))
109 (setq org-publish-project-alist
111 :base-directory "~/websites/stage.vanrenterghem.biz/source/"
112 :base-extension "org"
113 :include ("posts/sitemap.org")
114 :publishing-directory "~/websites/stage.vanrenterghem.biz/target"
115 :publishing-function org-mustache-html-publish-to-html
116 :mustache-template "~/websites/stage.vanrenterghem.biz/html/landing.mustache"
120 :html-head-include-default-style nil
128 :base-directory "~/websites/stage.vanrenterghem.biz/source/posts/"
129 :base-extension "org"
130 :publishing-directory "~/websites/stage.vanrenterghem.biz/target/posts"
131 :publishing-function org-mustache-html-publish-to-html
132 :mustache-template "~/websites/stage.vanrenterghem.biz/html/post.mustache"
133 :exclude "assets*\\|index.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp
134 :html-content-class nil
138 :sitemap-title "All posts"
139 :html-head-include-default-style nil
146 :sitemap-sort-folders ignore-errors
147 :sitemap-function my-blog-sitemap
148 ;:sitemap-function org-publish-sitemap-default
149 ;:sitemap-format-entry my-org-publish-sitemap-default-entry
150 :sitemap-sort-files anti-chronologically
151 :sitemap-filename "sitemap.org"
155 :base-directory "~/websites/stage.vanrenterghem.biz/source/assets/"
158 :publishing-directory "~/websites/stage.vanrenterghem.biz/target/assets/"
159 :publishing-function org-publish-attachment)
161 ("website" :components ("posts" "landing" "assets"))))