website/make.el

188 lines
5.5 KiB
EmacsLisp
Raw Normal View History

2021-02-25 19:56:21 +01:00
;;; Package -- make.el
;;; Commentary:
;;;
;;; Code:
(package-initialize)
2021-02-25 19:56:21 +01:00
(require 'org)
(require 'ox)
(require 'ox-html)
2021-02-25 19:56:21 +01:00
(dolist (d '("public_html"))
(unless (file-exists-p d)
(make-directory d)))
(require 'web-mode)
(require 'hcl-mode)
(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>"))
;; 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)
2021-03-07 14:36:26 +01:00
(defvar magic_rb/asset-include
"\\(ttf\\|svg\\|jpg\\|gif\\|png\\|css\\|js\\|el\\|nb\\|ipynb\\|pdf\\|xml\\)")
(defun magic_rb/source-with-name (name symbol property)
""
(string-trim
(org-element-property
property
(car (let ((path buffer-file-name))
(with-temp-buffer
(insert-file-contents path)
(org-element-map (org-element-parse-buffer) symbol
(lambda (object)
(let ((block-name (org-element-property :name object)))
(if (string-equal block-name name)
object
nil))))))))))
;; (org-element-map (org-element-parse-buffer) 'paragraph
;; (lambda (paragraph)
;; (let ((parent (org-element-property :parent paragraph)))
;; (and (eq (org-element-type parent) 'section)
;; (let ((first-child (car (org-element-contents parent))))
;; (eq first-child paragraph))
;; ;; Return value.
;; paragraph))))
2021-02-25 19:56:21 +01:00
(defvar org-publish-project-alist)
(setq org-publish-project-alist
`(
;; Blog
("redalder-blog-content"
:base-directory ,(expand-file-name "./blog/")
2021-02-25 19:56:21 +01:00
:base-extension "org"
:publishing-directory ,(expand-file-name "./public_html/blog")
2021-02-25 19:56:21 +01:00
:recursive t
:section-numbers nil
:with-toc nil
:with-date nil
:html-template ,(templated-html-load-template "./templates/blog.html")
2021-02-25 19:56:21 +01:00
:publishing-function org-html-publish-to-templated-html
:headline-levels 5
2021-03-07 14:36:26 +01:00
:exclude "^\\(index.org\\|*.inc\\)"
:auto-preamble t
:auto-sitemap t
:sitemap-folders ignore
:sitemap-style list
:sitemap-title "Magic_RB's blog"
2021-03-07 14:36:26 +01:00
:sitemap-filename "sitemap.inc"
:sitemap-sort-files anti-chronologically)
("redalder-blog-index"
:base-directory ,(expand-file-name "./blog/")
:root-directory ,(expand-file-name "./blog/")
2021-03-07 14:36:26 +01:00
:recursive t
:base-extension "org"
:exclude "^.*$"
2021-03-07 14:36:26 +01:00
:include ("index.org")
:publishing-directory ,(expand-file-name "./public_html/blog/")
2021-03-07 14:36:26 +01:00
:section-numbers nil
:with-toc nil
:with-date nil
:html-template ,(templated-html-load-template "./templates/blog-index.html")
2021-03-07 14:36:26 +01:00
: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)
;; Contact
("redalder-contact"
:base-directory ,(expand-file-name "./home")
:recursive nil
:base-extension "org"
:exclude "^.*$"
:include ("contact.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)
;; Links
("redalder-links"
:base-directory ,(expand-file-name "./home")
:recursive nil
:base-extension "org"
:exclude "^.*$"
:include ("links.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)
;; 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)
("nixng-examples"
:base-directory ,(expand-file-name "./nixng/examples/")
:base-extension "org"
:publishing-directory ,(expand-file-name "./public_html/")
:html-template ,(templated-html-load-template "./templates/example.html")
:publishing-function org-html-publish-to-templated-html)
;; 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-contact"
"redalder-links"))
("nixng-publish"
:components ("nixng-assets"
"nixng-examples"))))
2021-02-25 19:56:21 +01:00
(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"))))
2021-02-25 19:56:21 +01:00
(provide 'make)
;;; make.el ends here