ox-jamzattack.el (4693B)
1 ;;; ox-jamzattack.el --- ox-publish helper functions for jamzattack.xyz -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2020 Jamie Beardslee 4 5 ;; Author: Jamie Beardslee <jdb@jamzattack.xyz> 6 ;; Keywords: 7 8 ;; This program is free software; you can redistribute it and/or modify 9 ;; it under the terms of the GNU General Public License as published by 10 ;; the Free Software Foundation, either version 3 of the License, or 11 ;; (at your option) any later version. 12 13 ;; This program is distributed in the hope that it will be useful, 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ;; GNU General Public License for more details. 17 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 20 21 ;;; Commentary: 22 23 ;; 24 25 ;;; Code: 26 (require 'ox-publish) 27 (require 'ox-html) 28 (require 'cl-seq) 29 30 31 ;;; Format Spec 32 33 (defun ox-jamzattack:last-updated (file) 34 "Return the time that changes were commited in FILE." 35 (let* ((default-directory (file-name-directory file)) 36 (filename (file-relative-name file default-directory))) 37 (nth 0 38 (ignore-errors 39 (process-lines (executable-find "git") 40 "log" "-1" "--date=short" "--pretty=format:%cd" 41 filename))))) 42 43 (defun ox-jamzattack:format-spec (info) 44 "Return format specification for preamble and postamble. 45 INFO is a plist used as a communication channel. 46 47 Differences from `org-html-format-spec': 48 * %A - Author's name as a mailto link 49 * %M - Last modified time according to git" 50 (let ((timestamp-format (plist-get info :html-metadata-timestamp-format))) 51 `((?t . ,(org-export-data (plist-get info :title) info)) 52 (?s . ,(org-export-data (plist-get info :subtitle) info)) 53 (?d . ,(org-export-data (org-export-get-date info timestamp-format) 54 info)) 55 (?T . ,(format-time-string timestamp-format)) 56 (?a . ,(org-export-data (plist-get info :author) info)) 57 (?e . ,(mapconcat 58 (lambda (e) (format "<a href=\"mailto:%s\">%s</a>" e e)) 59 (split-string (plist-get info :email) ",+ *") 60 ", ")) 61 62 (?A . ,(format "<a href=\"mailto:%s\">%s</a>" 63 (plist-get info :email) 64 (org-export-data (plist-get info :author) info))) 65 (?M . ,(let ((file (plist-get info :input-file))) 66 (or (ox-jamzattack:last-updated file) 67 (format-time-string timestamp-format 68 (and file (file-attribute-modification-time 69 (file-attributes file))))))) 70 71 (?c . ,(plist-get info :creator)) 72 (?C . ,(let ((file (plist-get info :input-file))) 73 (format-time-string timestamp-format 74 (and file (file-attribute-modification-time 75 (file-attributes file)))))) 76 (?v . ,(or (plist-get info :html-validation-link) ""))))) 77 78 (advice-add 'org-html-format-spec :override 'ox-jamzattack:format-spec) 79 80 81 ;;; Sitemap 82 83 (defun ox-jamzattack:sitemap (project &optional sitemap-filename) 84 "If the file \".ring.org\" exists, include it in the sitemap. 85 86 This is advice for `org-publish-sitemap', and it should not be 87 called on its own. PROJECT and SITEMAP-FILENAME are both used to 88 determine where the sitemap is located." 89 (let* ((root (expand-file-name 90 (file-name-as-directory 91 (org-publish-property :base-directory project)))) 92 (sitemap-filename (concat root (or sitemap-filename "sitemap.org")))) 93 (with-current-buffer (find-file-noselect sitemap-filename) 94 (when (file-exists-p ".ring.org") 95 (goto-char (point-max)) 96 (insert "\n\n#+include: .ring.org") 97 (save-buffer))))) 98 99 (advice-add 'org-publish-sitemap :after 'ox-jamzattack:sitemap) 100 101 102 ;;; RSS 103 104 (use-package webfeeder 105 :straight t 106 :defer t) 107 108 (defun ox-jamzattack:make-rss (project &rest _ignored) 109 "Create an RSS feed for PROJECT." 110 (let* ((dir (expand-file-name 111 (file-name-as-directory 112 (org-publish-property :publishing-directory project)))) 113 (files (cl-remove "\\`\\(index\\|sitemap\\)\\.html\\'" 114 (mapcar 115 (lambda (file) 116 (replace-regexp-in-string 117 dir "" file)) 118 (directory-files-recursively 119 dir 120 "\\.html\\'")) 121 :test #'string-match-p)) 122 (project-name (car project)) 123 (url (format "https://%s.jamzattack.xyz" project-name)) 124 (title (pcase project-name 125 ("music" "Music") 126 ("blog" "The Yeet Log")))) 127 (when (cl-member project-name 128 '("blog" 129 "music") 130 :test #'string-equal) 131 (webfeeder-build 132 "rss.xml" 133 dir 134 url 135 files 136 :title title 137 :builder 'webfeeder-make-rss)))) 138 139 (advice-add 'org-publish :after #'ox-jamzattack:make-rss) 140 141 (provide 'ox-jamzattack) 142 ;;; ox-jamzattack.el ends here