+(setq org-export-time-stamp-file nil)
+(setq org-rss-use-entry-url-as-guid nil)
+
+(defun my-org-get-all-filetags ()
+ "Get list of filetags from all org-files in my-blog-posts-folder."
+ (let ((files (directory-files my-blog-posts-folder t nil nil nil))
+ tagslist x)
+ (save-window-excursion
+ (while (setq x (pop files))
+ (set-buffer (find-file-noselect x))
+ (mapc
+ (lambda (y)
+ (let ((tagfiles (assoc y tagslist)))
+ (if tagfiles
+ (setcdr tagfiles (cons x (cdr tagfiles)))
+ (add-to-list 'tagslist (list y x)))))
+ (my-org-get-filetags)))
+ tagslist)))
+
+(defun my-org-get-filetags ()
+ "Get list of filetags for current buffer"
+ (let ((ftags org-file-tags)
+ x)
+ (mapcar
+ (lambda (x)
+ (org-no-properties x))
+ ftags)))
+
+(defun my-blog-create-tags-files (plist)
+ "Create org files for each tag defined in FILETAGS in posts, storing them in my-blog-tags-folder."
+ (let* ((tagfolder (file-name-concat
+ (plist-get (cdr (assoc "landing" org-publish-project-alist)) :base-directory)))
+ (postfolder (file-name-concat
+ (plist-get (cdr (assoc "posts" org-publish-project-alist)) :base-directory)))
+ (relpostfolder (file-relative-name postfolder tagfolder)))
+ (unless (file-directory-p my-blog-tags-folder) (make-directory my-blog-tags-folder))
+ (with-temp-file (file-name-concat tagfolder "tag-index.org")
+ (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "tags-index.mustache") "\n"))
+ (insert (concat "#+TITLE: Blog - All tags\n"))
+ (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
+ (insert "\n")
+ (dolist (tag (sort (my-org-get-all-filetags) (lambda (x y) (string-lessp (car x) (car y))) ))
+ (insert (concat "- [[file:" (file-name-concat relpostfolder (concat "tag-" (car tag) ".org")) "][" (car tag) "]]\n")))))
+ (dolist (tag (my-org-get-all-filetags))
+ (with-temp-file (file-name-concat my-blog-tags-folder (concat "tag-" (car tag) ".org"))
+ (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "tags.mustache") "\n"))
+ (insert (concat "#+TITLE: " (car tag) "\n"))
+ (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
+ (insert "\n")
+ (insert (concat "# " (car tag) "\n\n"))
+ (dolist (tagfile (my-blog-sort-article-list (cdr tag) plist))
+ (let ((relpath (file-relative-name tagfile my-blog-posts-folder)));;not used
+ (message (concat "Processing " tagfile))
+ (insert (concat "- " (format "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry
+ (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date tagfile plist))
+ relpath
+ (org-publish-find-title tagfile plist))
+ "\n")))))))
+ ;(my-org-publish-sitemap-default-entry tagfile nil plist) "\n")))))))
+
+(defun my-org-publish-sitemap-default-entry (entry style project)
+ "My 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 "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry
+ (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date entry project))
+ entry
+ (org-publish-find-title entry project)))
+ ((eq style 'tree)
+ ;; Return only last subdir.
+ (file-name-nondirectory (directory-file-name entry)))
+ (t entry)))
+
+(defun my-blog-parse-sitemap-list (l)
+ "Convert the sitemap list in to a list of filenames."
+ (mapcar #'(lambda (i)
+ (let ((link (with-temp-buffer
+ (let ((org-inhibit-startup nil))
+ (insert (car i))
+ (org-mode)
+ (goto-char (point-min))
+ (org-element-link-parser)))))
+ (when link
+ (plist-get (cadr link) :path))))
+ (cdr l)))
+
+(defun my-blog-sort-article-list (l p)
+ "sort the article list anti-chronologically."
+ (sort l #'(lambda (a b)
+ (let ((d-a (org-publish-find-date a p))
+ (d-b (org-publish-find-date b p)))
+ (not (time-less-p d-a d-b))))))
+
+(defun my-blog-get-preview (file)
+ "Clips a section of a post in FILE to be used as preview in the sitemap.
+Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the first section between 2 blank lines."