~brettgilio/website

website/lisp/blog.el -rw-r--r-- 6.5 KiB
184f53c7 — Brett Gilio Updates 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
;;; blog.el --- description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020 Brett Gilio
;;
;; Author: Brett Gilio
;; Maintainer: Brett Gilio
;; Created: July 28, 2020
;; Modified: July 28, 2020
;; Version: 0.0.1
;; Keywords:
;; Homepage:
;; Package-Requires: ((emacs 26.3) (cl-lib "0.5"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;;  description
;;
;;; Code:

(require 'org)
(require 'ox)
(require 'blog-html)
(require 'blog-sitemap)
(require 'blog-rss)
(require 'xmlgen)

(defun parent-dir (file)
  "Return the parent directory of FILE."
  (unless (equal "/" file)
    (file-name-directory (directory-file-name file))))

(defvar blog-url "https://example.org")
(defvar blog-title "My Blog")
(defvar blog-root (parent-dir (or load-file-name buffer-file-name)))
(defvar blog-author-name user-full-name)
(defvar blog-author-email user-mail-address)
(defvar blog-content-license '("CC-BY-SA" . ""))
(defvar blog-code-license '("GNU GPLv3" . ""))
(defvar copyright-years "2020")

(defun project-dir (&optional dir)
  "Get the absolute path of DIR as if it is a directory in BLOG-ROOT."
  (expand-file-name (or dir "") blog-root))

(defun root-link (link)
  "Append LINK to BLOG-ROOT."
  (concat (file-name-as-directory blog-url) link))

(defun get-blog-project-alist ()
  `(("posts"
     :base-directory ,(project-dir "site/posts")
     :base-extension "org"
     :recursive t
     :exclude ,(regexp-opt '("rss.org" "sitemap.org"))
     :publishing-directory ,(project-dir "public/posts")
     :publishing-function blog-org-html-publish-to-html
     :html-link-home "/"
     :html-home/up-format ""
     :auto-sitemap t
     :html-format-headline-function blog-org-html-format-headline-function
     :sitemap-filename "sitemap.org"
     :sitemap-title ,blog-title
     :sitemap-sort-files anti-chronologically
     :sitemap-style list
     :sitemap-function blog-org-publish-sitemap
     :sitemap-format-entry blog-org-publish-sitemap-entry
     :author ,blog-author-name
     :email ,blog-author-email
     :with-creator t)
    ("pages"
     :base-directory ,(project-dir "site")
     :base-extension "org"
     :recursive t
     :exclude ,(regexp-opt '("posts" "rss.org"))
     :publishing-directory ,(project-dir "public")
     :publishing-function blog-org-html-publish-to-html
     :html-link-home "/"
     :html-home/up-format ""
     :html-format-headline-function blog-org-html-format-headline-function
     :author ,blog-author-name
     :email ,blog-author-email
     :with-creator t)
    ("rss"
     :base-directory ,(project-dir "site/posts")
     :base-extension "org"
     :exclude ".*"                ;; To exclude all files...
     :include ("rss.org")   ;; ... except index.org.
     :publishing-directory ,(project-dir "public")
     :publishing-function (blog-org-rss-publish-to-rss)
     :rss-extension "xml"
     :html-link-home ,blog-url
     :html-link-use-abs-url t
     :html-link-org-files-as-html t
     :title "Brett Gilio")
    ("rest"
     :base-directory ,(project-dir "site")
     :base-extension any
     :recursive t
     :exclude ".*\.org"
     :publishing-directory ,(project-dir "public")
     :publishing-function org-publish-attachment)))

(defun blog-publish-all ()
  "Publish the blog."
  (interactive)
  (let ((org-publish-project-alist (get-blog-project-alist))
        ;;(org-publish-timestamp-directory (project-dir ".timestamps"))
        (org-export-with-smart-quotes    t)
        (org-export-with-toc             nil)
        (org-html-doctype "html5")
        (org-html-divs '((preamble  "header" "preamble")
                         (content   "main"   "content")
                         (postamble "footer" "postamble")))
        (org-html-container-element "section")
        (org-html-link-home blog-root)
        (org-html-html5-fancy t)
        (org-html-checkbox-type 'html)
        (org-html-validation-link nil)
        (org-html-preamble t)
        (org-html-postamble t)
        (org-html-postamble-format `(("en"
                                      ,(xmlgen
                                        `(div
                                          (hr)
					  (p :class "noscript"
					     "Absolutely no Javascript loaded")
                                          (p :class "author" "Copyright 2020, %a <%e>")
                                          (p :class "lic-code"
                                             "Source code is licensed under "
                                             (a :href ,(cdr blog-code-license) ,(car blog-code-license)))
                                          (p :class "lic-content"
                                             "Content is licensed under "
                                             (a :href ,(cdr blog-content-license) ,(car blog-content-license)))
                                          (p :class "date" "Date: %d")
                                          (p :class "creator" "%c"))))))
        (org-html-preamble-format `(("en"
                                     ,(xmlgen
                                       `(div
                                         (div
                                          (a :href "/" "Index")
                                          (span :class "pre-sep" "|")
                                          (a :href "/projects.html" "Projects")
                                          (span :class "pre-sep" "|")
                                          (a :href "/planet.html" "Planet")
                                          (span :class "pre-sep" "|")
                                          (a :href "/services.html" "Services")
                                          (hr))
                                         (div :class "banner"
                                          (p :class "item" "Support free software by donating!")
                                          (a :class "item" :href "https://my.fsf.org/donate" "Free Software Foundation" :target "_blank")
                                          (a :class "item" :href "https://softwarefreedom.org/donate/" "Software Freedom Law Center" :target "_blank")
                                          (a :class "item" :href "https://sfconservancy.org/donate/" "Software Freedom Conservancy" :target "_blank"))

                                         (div :class "format-small"
                                              (a :href "/banner-source.html" "embed?"))))))))
    (org-publish-remove-all-timestamps)
    (delete-directory (project-dir "public") t)
    (org-publish-all)
    (message "Done publishing.")))

(provide 'blog)
;;;
;;; blog.el ends here