aboutsummaryrefslogtreecommitdiff
path: root/publish.el
blob: 0176c76374fe06686e60e2e9120a0eeece7b9222 (plain)
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
(require 'package)
(add-to-list 'package-archives '("gnu"   . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(eval-and-compile
  (setq use-package-always-ensure t
        use-package-expand-minimally t))

(use-package org
  :ensure org-plus-contrib)
(use-package ox-rss
  :after org)
(use-package htmlize
  :after org)
(use-package yaml-mode)
(use-package nix-mode)
(use-package plz)

(require 'org)
(require 'ox-html)
(require 'plz)

(setq webring (json-parse-string (plz 'get "https://aidang.cc/webring/https://jjanzen.ca")))
(defun create-webring-html (plist)
  (format "<div class='footer'><div class='footer-top'><span><a href='%s'>« %s</a></span><span>CSSA Web Ring</span><span><a href='%s'>%s »</a></span></div><div class='footer-bottom'>Copyright (C) Jacob Janzen 2024</div></div>"
          (gethash "url" (gethash "left" webring))
          (gethash "name" (gethash "left" webring))
          (gethash "url" (gethash "right" webring))
          (gethash "name" (gethash "right" webring))))

(defun my/org-publish-org-sitemap-format (entry style project)
  (cond ((not (directory-name-p entry))
         (format "(%s) [[file:blog/%s][%s]]\n"
                 (format-time-string "%Y-%m-%d"
                                     (org-publish-find-date entry project))
                 entry
                 (org-publish-find-title entry project)))))

(defun posts-rss-feed (title list)
  (concat
   "#+TITLE: " title "\n\n"
   (org-list-to-subtree list)))

(defun get-file-contents (filename)
  (with-temp-buffer
    (insert-file-contents filename)
    (buffer-string)))

(defun format-posts-rss-feed-entry (entry _style project)
  (let* (
         (title (org-publish-find-title entry project))
         (link (concat (file-name-sans-extension entry) ".html"))
         (file (org-publish--expand-file-name entry project))
         (pubdate (format-time-string (car org-time-stamp-formats)
                                      (org-publish-find-date entry project))))
    (message pubdate)
    (format "%s
:properties:
:rss_permalink: blog/%s
:pubdate: %s
:author: Jacob Janzen
:end:\n%s"
            title
            link
            pubdate
            (get-file-contents file))))

(defun publish-posts-rss-feed (plist filename dir)
  (if (equal "rss.org" (file-name-nondirectory filename))
      (org-rss-publish-to-rss plist filename dir)))

(defvar jj/html-preamble "<div class='topnav'><a href='/'>Home</a><a href='/projects.html'>Projects</a><a href='/blog'>Blog</a><a href='/dotfiles/'>Dotfiles</a><a href='/about.html'>About Me</a><a href='/rss.xml'>RSS</a><a href='https://git.jjanzen.ca/'>Git</a></div>")

(setq org-html-htmlize-output-type 'css)
(setq org-html-postamble 'create-webring-html)
(setq org-publish-project-alist
      `(
        ("org-core"
         :base-directory "~/website/"
         :base-extension "org"
         :publishing-directory "~/public_html/"
         :recursive t
         :publishing-function org-html-publish-to-html
         :with-toc nil
         :headline-levels 4
         :section-numbers nil
         :html-head "<link rel='stylesheet' href='/css/stylesheet.css' type='text/css'/>"
         :html-preamble ,jj/html-preamble)
        ("org-static-website"
         :base-directory "~/website/"
         :base-extension "txt\\|css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
         :publishing-directory "~/public_html"
         :recursive t
         :publishing-function org-publish-attachment)
        ("org-blog"
         :base-directory "~/blog/"
         :base-extension "org"
         :publishing-directory "~/public_html/blog"
         :recursive t
         :publishing-function org-html-publish-to-html
         :with-toc nil
         :with-properties t
         :with-date t
         :with-timestamps nil
         :headline-levels 4
         :section-numbers nil
         :html-head "<link rel='stylesheet' href='/css/stylesheet.css' type='text/css'/>"
         :html-preamble ,jj/html-preamble
         :auto-sitemap t
         :sitemap-filename "index.org"
         :sitemap-format-entry my/org-publish-org-sitemap-format
         :sitemap-sort-files anti-chronologically
         :sitemap-title "Blog")
        ("org-rss"
         :publishing-directory "~/public_html"
         :base-directory "~/blog/"
         :base-extension "org"
         :exclude "index.org"
         :publishing-function publish-posts-rss-feed
         :rss-extension "xml"
         :html-link-home "https://jjanzen.ca"
         :html-link-use-abs-url t
         :html-link-org-files-as-html t
         :auto-sitemap t
         :sitemap-function posts-rss-feed
         :sitemap-title "Jacob Janzen's Blog"
         :sitemap-filename "rss.org"
         :sitemap-style list
         :sitemap-sort-files anti-chronologically
         :sitemap-format-entry format-posts-rss-feed-entry)
        ("org-config"
         :base-directory "~/dotfiles/"
         :base-extension "org"
         :html-head "<link rel='stylesheet' href='/css/stylesheet.css' type='text/css'/>"
         :html-preamble ,jj/html-preamble
         :html-wrap-src-lines t
         :with-toc nil
         :section-numbers nil
         :recursive t
         :publishing-directory "~/public_html/dotfiles"
         :publishing-function org-html-publish-to-html
         :headline-levels 4
         :auto-preamble t)
        ("org-static-config"
         :base-directory "~/.dotfiles/"
         :base-extension "txt\\|css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
         :publishing-directory "~/public_html/dotfiles"
         :recursive t
         :publishing-function org-publish-attachment)
        ("org" :components ("org-core" "org-static-website" "org-config" "org-blog" "org-rss"))))
(org-publish-all t)