1#!/usr/bin/emacs --script23(setq my-website-public-dir (expand-file-name "./public/")4 my-content-dir (expand-file-name "./content/")5 my-blog-dir (expand-file-name "./content/blog/")6 my-templates-dir (expand-file-name "./templates/")78 my-website-home "/")910(setq package-user-dir (expand-file-name "./.packages"))1112(setq package-archives '(("melpa" . "https://melpa.org/packages/")13 ("elpa" . "https://elpa.gnu.org/packages/")))1415(setq use-package-always-ensure t16 backup-directory-alist `(("." . ,(expand-file-name "./.saves/")))17 tramp-auto-save-directory ".saves")1819(package-initialize)20(unless package-archive-contents21 (package-refresh-contents))22(unless (package-installed-p 'use-package)23 (package-install 'use-package))2425(require 'use-package)26(require 'ox-publish)2728(use-package htmlize)2930;; for code highlight31(use-package go-mode)32(use-package nginx-mode)33(use-package cc-mode)3435(use-package org-publish-rss36 :vc (org-publish-rss37 :url "https://git.sr.ht/~taingram/org-publish-rss"38 :rev :newest))3940(setq org-ascii-text-width 10041 org-export-with-section-numbers nil42 org-export-with-creator nil43 org-export-with-email nil44 org-export-with-author nil45 org-export-with-date t46 org-html-validation-link nil47 org-html-html5-fancy t48 org-html-doctype "xhtml5"49 org-html-head-include-scripts nil50 org-html-htmlize-output-type 'css51 org-html-head-include-default-style nil52 org-html-head "<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/orgmode.min.css\" />"53 org-html-viewport '((width "device-width")54 (initial-scale "1")))5556(setq org-publish-timestamp-directory (concat default-directory ".org-timestamps/")57 org-export-time-stamp-file nil58 org-export-global-macros '(("timestamp" . "@@html:<span class=\"timestamp\">$1</span>@@")))5960(setq org-confirm-babel-evaluate nil)61(org-babel-do-load-languages62 'org-babel-load-languages63 '((shell . t)64 (python . t)65 (emacs-lisp . t)))666768(defun website-header (info)69 (with-temp-buffer70 (insert-file-contents (concat my-templates-dir "header.html"))71 (buffer-string)))7273(defun website-footer (info)74 (with-temp-buffer75 (insert-file-contents (concat my-templates-dir "footer.html"))76 (buffer-string)))7778(defun my-blog-articles-preprocessor (project-plist)79 (message "In the articles preprocessor."))8081(defun my-blog-articles-postprocessor (project-plist)82 (org-publish-rss project-plist)83 (message "In the articles postprocessor."))8485;; ------ Sitemap ---------86(defun file-in-categories (filename categories)87 (with-temp-buffer88 (insert-file-contents filename)89 (delay-mode-hooks (org-mode))90 (member (downcase (org-get-category)) categories)))9192(defun file-is-blog-post (filename)93 (file-in-categories filename '("blog")))9495(defun my-sitemap-entry (entry style project)96 (message (plist-get (cdr project) :base-directory))97 (if (and (not (directory-name-p entry))98 (file-is-blog-post (expand-file-name entry (plist-get (cdr project) :base-directory))))99 (let* ((date (org-publish-find-date entry project)))100 (format "{{{timestamp(%s)}}}[[file:%s][%s]]"101 (if date (format-time-string "[%Y-%m-%d] " date) "")102 entry103 (org-publish-find-title entry project)))104 ""))105106(defun my-sitemap-function (title list)107 (let ((fixedlist (seq-filter (lambda (i) ( if (listp i) (not (member "" i)) t)) list)))108 (org-list-to-org fixedlist)))109110(defun my-blog-org-export-format-drawer (name content)111 (concat "<div class=\"drawer " (downcase name) "\">\n"112 ;; "<h6>" (capitalize name) "</h6>\n"113 content114 "\n</div>"))115116(defun org-html-publish-skipdraft (plist filename pub-dir)117 (with-current-buffer (find-file-noselect filename)118 (if (file-in-categories filename '("draft"))119 (message "Skipping draft file: %s" filename)120 (org-html-publish-to-html plist filename pub-dir))))121122(setq org-publish-project-alist123 `(("org-site:main"124 :recursive nil125 :base-directory ,my-content-dir126 :publishing-directory ,my-website-public-dir127 :base-extension "org"128129 :with-drawers t130 :html-format-drawer-function my-blog-org-export-format-drawer131132 :publishing-function org-html-publish-skipdraft)133134 ("org-site:blog"135 :recursive t136137 :base-directory ,my-blog-dir138 :publishing-directory ,(expand-file-name "blog" my-website-public-dir)139 :publishing-function org-html-publish-skipdraft140 :base-extension "org"141 :html-link-home ,my-website-home142 :html-link-up "/blog"143144 :htmlized-source t145146 :html-preamble website-header147 :html-postamble website-footer148149 :completion-function my-blog-articles-postprocessor150 :preparation-function my-blog-articles-preprocessor151152 :auto-rss t153154 :auto-sitemap t155 :sitemap-filename "sitemap.inc"156 :sitemap-format-entry my-sitemap-entry157 :sitemap-function my-sitemap-function158 :sitemap-style list159 :sitemap-sort-files anti-chronologically160161 :makeindex nil162163 :with-drawers t164 :html-format-drawer-function my-blog-org-export-format-drawer165166 :rss-title "Lindsay"167 :rss-description ""168 :rss-with-content all169 :rss-file "rss.xml"170 :rss-filter-function file-is-blog-post)171172 ("org-site:static"173 :recursive t174 :base-directory ,my-content-dir175 :base-extension "txt\\|html\\|md\\|css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|ico\\|xml"176177 :publishing-directory ,my-website-public-dir178 :publishing-function org-publish-attachment179 :time-stamp-file nil)180 ("org-site" :components ("org-site:blog" "org-site:main" "org-site:static"))))181182(org-publish-rss "org-site")183(org-publish "org-site")