]> git.vanrenterghem.biz Git - www2.vanrenterghem.biz.git/blob - maak-website.el
Gebruik juist filetags formaat.
[www2.vanrenterghem.biz.git] / maak-website.el
1 (require 'ox-publish)
2 (load "~/.emacs.d/lisp/mustache-html.el")
4 (setq org-html-doctype "html5")
5 (setq org-html-head-include-default-style nil)
6 (setq org-html-htmlize-output-type 'css) ; default: 'inline-css
9 (defun my-org-publish-sitemap-default-entry (entry style project)
10   "My format for site map ENTRY, as a string.
11 ENTRY is a file name.  STYLE is the style of the sitemap.
12 PROJECT is the current project."
13   (cond ((not (directory-name-p entry))
14          (format "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry
15                  (format-time-string "%e %b %Y" (org-publish-find-date entry project))
16                  entry
17                  (org-publish-find-title entry project)))
18         ((eq style 'tree)
19          ;; Return only last subdir.
20          (file-name-nondirectory (directory-file-name entry)))
21         (t entry)))
23 (defun my-blog-parse-sitemap-list (l)
24   "Convert the sitemap list in to a list of filenames."
25   (mapcar #'(lambda (i)
26               (let ((link (with-temp-buffer
27                             (let ((org-inhibit-startup nil))
28                               (insert (car i))
29                               (org-mode)
30                               (goto-char (point-min))
31                               (org-element-link-parser)))))
32                 (when link
33                   (plist-get (cadr link) :path))))
34           (cdr l)))
36 (defun my-blog-sort-article-list (l p)
37   "sort the article list anti-chronologically."
38   (sort l #'(lambda (a b)
39               (let ((d-a (org-publish-find-date a p))
40                     (d-b (org-publish-find-date b p)))
41                 (not (time-less-p d-a d-b))))))
43 (defun my-blog-get-preview (file)
44   "Clips a section of a post in FILE to be used as preview in the sitemap.
45 Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the first section between 2 blank lines."
46   (with-temp-buffer
47     (insert-file-contents file)
48     (goto-char (point-min))
49     (let* ((beg (or (re-search-forward "^#\\+BEGIN_PREVIEW$" nil t 1)
50                     (re-search-forward "^$")))
51            (end (or (if (re-search-forward "^#\\+END_PREVIEW$" nil t 1)
52                         (match-beginning 0))
53                     (progn (goto-char (+ 1 beg))
54                            (re-search-forward "^$" nil t 2)))))
55       (buffer-substring beg end))))
57 (defun my-blog-sitemap (title list)
58   "Generate the sitemap landing page for my blog."
59   (my-plain-publish-sitemap-default title list)
60   (with-temp-buffer
61     ;; mangle the parsed list given to us into a plain lisp list of files
62     (let* ((filenames (my-blog-parse-sitemap-list list))
63            (project-plist (assoc "posts" org-publish-project-alist))
64            (articles (my-blog-sort-article-list filenames project-plist)))
65       (dolist (file filenames)
66         (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
67                (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/posts/"))
68                (title (org-publish-find-title file project-plist))
69                (date (format-time-string (car org-time-stamp-formats) (org-publish-find-date file project-plist)))
70                (preview (my-blog-get-preview abspath))
71                )
72           ;; insert a horizontal line before every post, kill the first one
73           ;; before saving
74           (insert "-----\n")
75           (insert (concat "* [[file:" relpath "][" title "]]\n"))
76           ;; add properties for `ox-rss.el' here
77                                         ;(let ((rss-permalink (concat (file-name-sans-extension relpath) ".html"))
78                                         ;      (rss-pubdate date))
79                                         ;  (org-set-property "RSS_PERMALINK" rss-permalink)
80                                         ;  (org-set-property "PUBDATE" rss-pubdate))
81           ;; insert the date, preview, & read more link
82           (insert (concat "Published: " date "\n\n"))
83           (insert preview)
84                                         ;(insert (concat "#+INCLUDE: \"" relpath "\" :only-contents t :lines \"1-10\"\n"))
85           (insert "\n")
86           (insert (concat "[[file:" relpath "][Read More...]]\n"))))
87       ;; kill the first hrule to make this look OK
88       (goto-char (point-min))
89       (let ((kill-whole-line t)) (kill-line))
90       ;; insert a title and save
91       (insert "#+OPTIONS: title:nil\n")
92       (insert "#+TITLE: Blog\n")
93       (insert "#+AUTHOR: Frederik Vanrenterghem\n")
94       (insert "#+EMAIL: frederik@vanrenterghem.biz\n")
95       (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
96       (insert "#+mustache-template: ~/websites/stage.vanrenterghem.biz/html/post-index.mustache\n")
97       (insert "\n")
98       (buffer-string))))
100 (defun my-plain-publish-sitemap-default (title list)
101   "Create a simple site map, as a string.
102 TITLE is the title of the site map.  LIST is an internal
103 representation for the files to include, as returned by
104 `org-list-to-lisp'."
105   (with-temp-file "~/websites/stage.vanrenterghem.biz/source/sitemap.org"
106     (let* ((filenames (my-blog-parse-sitemap-list list))
107            (project-plist (assoc "posts" org-publish-project-alist))
108            (articles (my-blog-sort-article-list filenames project-plist)))
109       (dolist (file filenames)
110         (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
111                (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/"))
112                (title (org-publish-find-title file project-plist))
113                (date (format-time-string "%e %b %Y" (org-publish-find-date file project-plist))))
114           (insert (concat "* [[file:" relpath "][" date " - " title "]]\n"))))
115       (goto-char (point-min))
116       (insert "#+OPTIONS: ^:nil\n")))) ; do not use underscores as subscript
118 (setq org-publish-project-alist
119       '(("landing"
120          :base-directory "~/websites/stage.vanrenterghem.biz/source/"
121          :base-extension "org"
122          ;:include ("posts/sitemap.org")
123          :publishing-directory "~/websites/stage.vanrenterghem.biz/target"
124          :publishing-function org-mustache-html-publish-to-html
125          :mustache-template "~/websites/stage.vanrenterghem.biz/html/landing.mustache"
126          :headline-levels 2
127          :section-numbers nil
128          :with-toc nil
129          :with-title nil
130          :html-content-class nil
131          :html-head-include-default-style nil
132          :html-head nil
133          :html-divs nil
134          :html-preamble nil
135          :html-postamble nil
136          )
138         ("posts"
139          :base-directory "~/websites/stage.vanrenterghem.biz/source/posts/"
140          :base-extension "org"
141          :publishing-directory "~/websites/stage.vanrenterghem.biz/target/posts"
142          :publishing-function org-mustache-html-publish-to-html
143          :mustache-template "~/websites/stage.vanrenterghem.biz/html/post.mustache"
144          :exclude "html*\\|assets*\\|index.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp
145          :html-content-class nil
146          :section-numbers nil
147          :with-toc nil
148          :with-title nil
149          :sitemap-title "All posts"
150          :html-head-include-default-style nil
151          :html-head nil
152          :html-divs nil
153          :recursive t
154          :auto-sitemap t
155          :html-preamble nil
156          :html-postamble nil
157          :sitemap-sort-folders ignore-errors
158          :sitemap-function my-blog-sitemap
159          ;:sitemap-function org-publish-sitemap-default
160          ;:sitemap-format-entry my-org-publish-sitemap-default-entry
161          :sitemap-sort-files anti-chronologically
162          :sitemap-filename "sitemap.org"
163          )
165         ("assets"
166          :base-directory "~/websites/stage.vanrenterghem.biz/source/assets/"
167          :base-extension any
168          :recursive t
169          :publishing-directory "~/websites/stage.vanrenterghem.biz/target/assets/"
170          :publishing-function org-publish-attachment)
172         ("website" :components ("posts" "landing" "assets"))))