mirror of
https://git.sr.ht/~magic_rb/website
synced 2024-11-22 00:04:20 +01:00
209 lines
7.2 KiB
EmacsLisp
209 lines
7.2 KiB
EmacsLisp
;; -*- lexical-binding: t -*-
|
|
;;; Package -- make.el
|
|
;;; Commentary:
|
|
;;;
|
|
|
|
;;; Code:
|
|
(package-initialize)
|
|
|
|
(require 'org)
|
|
|
|
(require 'cl-lib)
|
|
|
|
(require 'ox)
|
|
(require 'ox-html)
|
|
|
|
(dolist (d '("public_html"))
|
|
(unless (file-exists-p d)
|
|
(make-directory d)))
|
|
|
|
(require 'org-special-block-extras)
|
|
(add-hook #'org-mode-hook #'org-special-block-extras-mode)
|
|
|
|
(defun my-org--support-special-blocks-with-args (backend)
|
|
(let ((fbackend (if (equal backend '(templated-html)) 'html backend)))
|
|
`(,fbackend)))
|
|
(advice-add 'org--support-special-blocks-with-args :filter-args #'my-org--support-special-blocks-with-args)
|
|
|
|
(ignore-errors (require 'ox-thtml))
|
|
|
|
;; https://alhassy.github.io/AlBasmala.html#Floating-TOC
|
|
(advice-add 'org-html--translate :before-until 'display-toc-as-toc)
|
|
(defun display-toc-as-toc (phrase info)
|
|
(when (equal phrase "Table of Contents")
|
|
"<a>
|
|
TOC
|
|
</a>"))
|
|
|
|
(require 'extra-blocks)
|
|
|
|
;; DOES NOT WORK https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors
|
|
|
|
(setq org-export-with-sub-superscripts '{}
|
|
org-export-headline-levels 6
|
|
; emacs-htmlize does not work when Emacs is ran in =script= mode unfortunately
|
|
;; org-html-html5-fancy t
|
|
org-html-htmlize-output-type 'css
|
|
indent-tabs-mode nil)
|
|
(setq-default indent-tabs-mode nil)
|
|
|
|
(defvar magic_rb/asset-include
|
|
"\\(ttf\\|svg\\|jpg\\|gif\\|png\\|css\\|js\\|el\\|nb\\|ipynb\\|pdf\\|xml\\|woff2\\)")
|
|
|
|
(defun org-export-add-target-blank-to-http-links (text backend info)
|
|
"Add target=\"_blank\" to external links."
|
|
(when (and
|
|
(org-export-derived-backend-p backend 'html)
|
|
(string-match "href=\"https?[^\"]+" text)
|
|
(not (string-match "target=\"" text)))
|
|
(string-match "<a " text)
|
|
(replace-match "<a target=\"_blank\" " nil nil text)))
|
|
|
|
(defun org-publish-sitemap-filtered (exclude)
|
|
"Publish sitemap filtered using EXCLUDE."
|
|
(lambda (title list)
|
|
(let ((filtered-list
|
|
(seq-filter
|
|
(lambda (x)
|
|
(if (equal x 'unordered)
|
|
t
|
|
(pcase (with-temp-buffer
|
|
(let ((org-inhibit-startup nil))
|
|
(insert (car x))
|
|
(org-mode)
|
|
(goto-char (point-max))
|
|
(org-element-context)))
|
|
(`nil (error "Unreachable"))
|
|
(link (not (seq-contains-p
|
|
exclude
|
|
(plist-get (car (cdr link)) :path)
|
|
#'string-equal))))))
|
|
list)))
|
|
(org-publish-sitemap-default title filtered-list))))
|
|
|
|
(defun org-publish-sitemap-entry-with-date (entry style project)
|
|
"Default format for site map ENTRY, as a string.
|
|
ENTRY is a file name. STYLE is the style of the sitemap.
|
|
PROJECT is the current project."
|
|
(cond ((not (directory-name-p entry))
|
|
(format "%s [[file:%s][%s]]"
|
|
(format-time-string "%Y-%m-%d" (org-publish-find-date entry project))
|
|
entry
|
|
(org-publish-find-title entry project)))
|
|
((eq style 'tree)
|
|
;; Return only last subdir.
|
|
(file-name-nondirectory (directory-file-name entry)))
|
|
(t entry)))
|
|
|
|
(defvar org-publish-project-alist)
|
|
(setq org-publish-project-alist
|
|
`(
|
|
;; Blog
|
|
("redalder-blog-content"
|
|
:base-directory ,(expand-file-name "./blog/")
|
|
:base-extension "org"
|
|
:publishing-directory ,(expand-file-name "./public_html/blog")
|
|
:recursive t
|
|
:section-numbers nil
|
|
:with-toc nil
|
|
:with-date nil
|
|
:html-template ,(templated-html-load-template "./templates/blog.html")
|
|
:publishing-function org-html-publish-to-templated-html
|
|
:headline-levels 5
|
|
:exclude "^\\(index.org\\|*.inc\\)"
|
|
:auto-preamble t
|
|
:auto-sitemap t
|
|
:sitemap-folders ignore
|
|
:sitemap-style list
|
|
:sitemap-title "Magic_RB's blog"
|
|
:sitemap-filename "sitemap.inc"
|
|
:sitemap-sort-files anti-chronologically
|
|
:sitemap-function ,(org-publish-sitemap-filtered '())
|
|
:sitemap-format-entry org-publish-sitemap-entry-with-date)
|
|
("redalder-blog-index"
|
|
:base-directory ,(expand-file-name "./blog/")
|
|
:root-directory ,(expand-file-name "./blog/")
|
|
:recursive t
|
|
:base-extension "org"
|
|
:exclude "^.*$"
|
|
:include ("index.org")
|
|
:publishing-directory ,(expand-file-name "./public_html/blog/")
|
|
:section-numbers nil
|
|
:with-toc nil
|
|
:with-date nil
|
|
:html-template ,(templated-html-load-template "./templates/blog-index.html")
|
|
:publishing-function org-html-publish-to-templated-html)
|
|
("redalder-blog"
|
|
:components ("redalder-blog-content" "redalder-blog-index"))
|
|
|
|
|
|
;; Homepage
|
|
("redalder-homepage"
|
|
:base-directory ,(expand-file-name "./home")
|
|
:recursive nil
|
|
:base-extension "org"
|
|
:exclude "^.*$"
|
|
:include ("index.org")
|
|
:with-toc nil
|
|
:publishing-directory ,(expand-file-name "./public_html/")
|
|
:html-template ,(templated-html-load-template "./templates/index.html")
|
|
:publishing-function org-html-publish-to-templated-html)
|
|
|
|
|
|
("redalder-subpages"
|
|
:base-directory ,(expand-file-name "./home")
|
|
:recursive nil
|
|
:base-extension "org"
|
|
:exclude "^.*$"
|
|
:include ("contact.org" "links.org" "projects.org")
|
|
:with-toc nil
|
|
:publishing-directory ,(expand-file-name "./public_html/")
|
|
:html-template ,(templated-html-load-template "./templates/empty.html")
|
|
:publishing-function org-html-publish-to-templated-html)
|
|
|
|
("redalder-projects"
|
|
:base-directory ,(expand-file-name "./home/projects")
|
|
:recursive nil
|
|
:base-extension "org"
|
|
:with-toc nil
|
|
:publishing-directory ,(expand-file-name "./public_html/projects")
|
|
:html-template ,(templated-html-load-template "./templates/empty.html")
|
|
:publishing-function org-html-publish-to-templated-html)
|
|
|
|
;; Static images and css and js for redalder.org
|
|
("redalder-assets"
|
|
:base-directory ,(expand-file-name "./assets/")
|
|
:publishing-directory ,(expand-file-name "./public_html/")
|
|
:recursive t
|
|
:base-extension ,magic_rb/asset-include
|
|
:publishing-function org-publish-attachment)
|
|
|
|
;; Static images and css and js for nixng.org
|
|
("nixng-assets"
|
|
:base-directory ,(expand-file-name "./assets/")
|
|
:publishing-directory ,(expand-file-name "./public_html/")
|
|
:recursive t
|
|
:base-extension ,magic_rb/asset-include
|
|
:publishing-function org-publish-attachment)
|
|
|
|
;; top-level trigger
|
|
("redalder-publish"
|
|
:components ("redalder-blog"
|
|
"redalder-assets"
|
|
"redalder-homepage"
|
|
"redalder-subpages"
|
|
"redalder-projects"))
|
|
|
|
("nixng-publish"
|
|
:components ("nixng-assets"))))
|
|
|
|
(defun magic_rb/publish-website (website)
|
|
"Publish WEBSITE."
|
|
(cond ((string= website "redalder.org")
|
|
(org-publish "redalder-publish" t))
|
|
((string= website "nixng.org")
|
|
(org-publish "nixng-publish"))))
|
|
|
|
(provide 'make)
|
|
;;; make.el ends here
|