+(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."
+ (unless (file-directory-p my-blog-tags-folder) (make-directory my-blog-tags-folder))
+ (with-temp-file (file-name-concat my-blog-source-folder "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) #'<))
+ (insert (concat "- [[file:" (file-name-concat my-blog-posts-folder (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 (cdr tag))
+ (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")))))))
+