kristells-ssg/build-site.el
Kristell Lymilark 53977c71f7 initial commit
2024-08-04 22:40:31 -04:00

103 lines
4.9 KiB
EmacsLisp

;; Set the package installation directory so that packages aren't stored in the
;; ~/.emacs.d/elpa path.
(require 'package)
(setq package-user-dir (expand-file-name "./.packages"))
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("elpa" . "https://elpa.gnu.org/packages/")))
;; This initializes the package system
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;; Install dependencies
(package-install 'htmlize)
(package-install 'ox-rss)
(package-install 'fontawesome)
(package-install 'webfeeder)
;; Load the publishing system/RSS system
(require 'ox-publish)
(require 'ox-rss)
;; Customization for the HTML output
(setq org-html-validation-link nil ;; Don't show validation link
org-html-head-include-scripts nil ;; Use our own scripts
org-html-head-include-default-style nil ;; Use our own styles
org-html-head "<link rel=\"stylesheet\" href=\"https://cdn.simplecss.org/simple.min.css\" />")
;; This is where we define the publish alist
(setq org-publish-project-alist
(list
(list "org-site:main"
:author "{Y/N}" ;; Your name goes here
:recursive t
:makeindex t
:base-directory "./content" ;; The base directory for the project, relative to the build-site file
:publishing-function 'org-html-publish-to-html
:publishing-directory "./public" ;; Where you want your website to be placed
:with-author t ;; Include the author name, either from the .org file, or within here
:with-creator t ;; Include Emacs and Org versions in footer
:with-toc nil ;; Do not include a table of contents on each page, set to t to include it
:section-numbers nil ;; Don't put numbers by the headings
:time-stamp-file nil)))
(add-to-list
'org-publish-project-alist
'("org-site:blog"
:base-directory "./content/blog"
:base-extension "org"
:auto-sitemap t ;; Generates the sitemap for the blog portion of this
:sitemap-filename "sitemap.org" ;; The name of your sitemap file, not super important just make it memorable
:sitemap-title "" ;; Leave the title blank if you don't want it showing up above the page
:sitemap-sort-files chronologically ;; Sorts them by ascending date, anti-chronologically would be newest first, and alphabetically would be alphabetical
:html-link-use-abs-url t
:publishing-directory "./public/blog" ;; What directory your want the html files appearing in
:section-numbers nil ;; Don't put numbers by the headings
:table-of-contents nil))
; (add-to-list
; 'org-publish-project-alist
; '("homepage_rss"
; :base-directory "./content/blog"
; :base-extension "org"
; :rss-image-url "https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/RSS_icon.svg/36px-RSS_icon.svg.png"
; :html-link-home "http://klymilark.fallcounty.monster/blog"
; :html-link-use-abs-url t
; :rss-extension "xml"
; :publishing-directory "./public/blog/"
; :publishing-function (org-rss-publish-to-rss)
; :section-numbers nil
; :exclude ".*"
; :include ("index.org")
; :table-of-contents nil))
;; That section is commented out, though I may come back to it, so it's staying for now
;; This section is to generate the RSS feed
(defun dw/rss-extract-date (html-file)
"Extract the post date from an HTML file."
(with-temp-buffer
(insert-file-contents html-file)
(let* ((dom (libxml-parse-html-region (point-min) (point-max)))
(date-string (dom-text (car (dom-by-class dom "date"))))
(parsed-date (parse-time-string date-string))
(day (nth 3 parsed-date))
(month (nth 4 parsed-date))
(year (nth 5 parsed-date))))))
(setq webfeeder-date-function #'dw/rss-extract-date)
(webfeeder-build "rss.xml"
"./public"
"http://your-domain.tld" ;; Replace with your blog's URL
(mapcar (lambda (file) (concat "blog/" file))
(let ((default-directory (expand-file-name "./public/blog/")))
(directory-files-recursively "./" ".*\\.html$")))
:builder 'webfeeder-make-rss
:title "Your Blog's Title" ;; Replace with your blog's title
:description "Your blog's description" ;; Replace with your blog's description
:author "Y/N") ;; Replace with your name
;; Generate the site output
(org-publish-all t)
(message "Build complete!")