Update the way the blog is generated
Instead of using a dynamic block to generate the index, use a sitemap function.
This commit is contained in:
parent
10cf6bbc49
commit
830432c238
5 changed files with 133 additions and 108 deletions
1
Cask
1
Cask
|
@ -2,4 +2,5 @@
|
||||||
(source melpa)
|
(source melpa)
|
||||||
(source org)
|
(source org)
|
||||||
|
|
||||||
|
(depends-on "htmlize")
|
||||||
(depends-on "org-plus-contrib")
|
(depends-on "org-plus-contrib")
|
||||||
|
|
20
GNUmakefile
20
GNUmakefile
|
@ -1,16 +1,18 @@
|
||||||
.PHONY: site html css
|
.PHONY: publish html css
|
||||||
|
|
||||||
site: html css
|
site: html css
|
||||||
|
|
||||||
html: public_html/index.html
|
html:
|
||||||
|
@echo "Publishing..."
|
||||||
|
cask emacs --quick --batch --load publish.el --funcall org-publish-all
|
||||||
|
|
||||||
css: public_html/assets/css/main.css
|
css: public_html/assets/css/main.css
|
||||||
|
|
||||||
public_html/%.html: %.org
|
public/assets/css/%.css: src/less/%.less
|
||||||
cask emacs -batch \
|
|
||||||
-funcall package-initialize \
|
|
||||||
-load project-config.el \
|
|
||||||
-funcall publish-ryuslash.org
|
|
||||||
|
|
||||||
public_html/assets/css/%.css: src/less/%.less
|
|
||||||
lessc $^ $@
|
lessc $^ $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo "Cleaning up..."
|
||||||
|
@rm -rvf *.elc
|
||||||
|
@rm -rvf public
|
||||||
|
@rm -rvf ~/.org-timestamps/*
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
#+TITLE: ryuslash.org
|
|
||||||
#+STARTUP: showall
|
|
||||||
#+OPTIONS: toc:nil num:nil
|
|
||||||
#+HTML_LINK_UP:
|
|
||||||
#+HTML_LINK_HOME: https://ryuslash.org/
|
|
||||||
|
|
||||||
#+BEGIN: blog-posts
|
|
||||||
|
|
||||||
#+END:
|
|
|
@ -1,90 +0,0 @@
|
||||||
(require 'ox-publish)
|
|
||||||
(require 'ox-rss)
|
|
||||||
|
|
||||||
(setq org-export-exclude-tags '("noexport" "draft"))
|
|
||||||
|
|
||||||
(setq org-publish-project-alist
|
|
||||||
'(("ryuslash.org"
|
|
||||||
:base-directory "."
|
|
||||||
:publishing-directory "public_html"
|
|
||||||
:exclude "\\`README.org\\'"
|
|
||||||
:base-extension "org"
|
|
||||||
:publishing-function org-html-publish-to-html
|
|
||||||
:html-head "<link rel=\"stylesheet\" href=\"assets/css/main.css\" type=\"text/css\"/>"
|
|
||||||
:html-link-home "https://ryuslash.gitlab.io/ryuslash.org/"
|
|
||||||
:html-link-up nil
|
|
||||||
:html-link-user-abs-url t)
|
|
||||||
("ryuslash.org Posts"
|
|
||||||
:base-directory "posts"
|
|
||||||
:publishing-directory "public_html/posts"
|
|
||||||
:exclude "\\`README.org\\'"
|
|
||||||
:base-extension "org"
|
|
||||||
:publishing-function org-html-publish-to-html
|
|
||||||
:html-head "<link rel=\"stylesheet\" href=\"../assets/css/main.css\" type=\"text/css\"/>"
|
|
||||||
:html-link-home "https://ryuslash.gitlab.io/ryuslash.org/"
|
|
||||||
:html-link-up "../"
|
|
||||||
:html-link-user-abs-url t
|
|
||||||
:html-preamble (lambda (_)
|
|
||||||
(project-config-print-reading-time
|
|
||||||
(project-config-reading-time (buffer-file-name)))))
|
|
||||||
("ryuslash-rss"
|
|
||||||
:base-directory "."
|
|
||||||
:publishing-directory "public_html"
|
|
||||||
:exclude ".*"
|
|
||||||
:include ("index.org")
|
|
||||||
:base-extension "org"
|
|
||||||
:publishing-function org-rss-publish-to-rss)))
|
|
||||||
|
|
||||||
(defun publish-ryuslash.org ()
|
|
||||||
(with-current-buffer (find-file "index.org")
|
|
||||||
(org-update-all-dblocks)
|
|
||||||
(save-buffer))
|
|
||||||
(org-publish-all))
|
|
||||||
|
|
||||||
(defun project-config-parse-element (org-element)
|
|
||||||
(pcase org-element
|
|
||||||
(`(keyword ,something) (cons (intern (plist-get something :key))
|
|
||||||
(plist-get something :value)))
|
|
||||||
(`(paragraph ,something) (cons
|
|
||||||
'BODY
|
|
||||||
(buffer-substring-no-properties
|
|
||||||
(plist-get something :contents-begin)
|
|
||||||
(plist-get something :contents-end))))))
|
|
||||||
|
|
||||||
(defun project-config-parse-document (document)
|
|
||||||
(with-current-buffer (find-file document)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(let (alist)
|
|
||||||
(while (not (alist-get 'BODY alist nil nil #'equal))
|
|
||||||
(setq alist (cons (project-config-parse-element (org-element-at-point))
|
|
||||||
alist))
|
|
||||||
(org-forward-element))
|
|
||||||
alist)))
|
|
||||||
|
|
||||||
(defun project-config-print-reading-time (time)
|
|
||||||
(format "%d minute%s"
|
|
||||||
time
|
|
||||||
(if (= time 1) "" "s")))
|
|
||||||
|
|
||||||
(defun project-config-print-element (alist)
|
|
||||||
(format "* %s\n :PROPERTIES:\n :ID: %s\n :PUBDATE: %s\n :END:\n\n %s\n[[file:%s][Read more (%s)]]\n"
|
|
||||||
(alist-get 'TITLE alist)
|
|
||||||
(alist-get 'ID alist)
|
|
||||||
(alist-get 'PUBDATE alist)
|
|
||||||
(alist-get 'BODY alist)
|
|
||||||
(alist-get 'NAME alist)
|
|
||||||
(project-config-print-reading-time (alist-get 'LENGTH alist))))
|
|
||||||
|
|
||||||
(defun project-config-reading-time (file)
|
|
||||||
(with-current-buffer (find-file file)
|
|
||||||
(max 1 (/ (count-words (point-min) (point-max)) 228))))
|
|
||||||
|
|
||||||
(defun project-config-print-file (file)
|
|
||||||
(project-config-print-element
|
|
||||||
(append `((NAME . ,(concat "posts/" file))
|
|
||||||
(LENGTH . ,(project-config-reading-time (concat "posts/" file))))
|
|
||||||
(project-config-parse-document (concat "posts/" file)))))
|
|
||||||
|
|
||||||
(defun org-dblock-write:blog-posts (params)
|
|
||||||
(let ((files (cl-remove-if (lambda (item) (string-prefix-p "." item)) (directory-files "posts"))))
|
|
||||||
(insert (format "%s" (apply #'concat (mapcar #'project-config-print-file files))))))
|
|
121
publish.el
Normal file
121
publish.el
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
;;; publish.el --- Publishing configuration for ryuslash.org -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;; Copyright (C) 2020 Tom Willemse
|
||||||
|
|
||||||
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||||
|
;; Keywords:
|
||||||
|
|
||||||
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'ox-publish)
|
||||||
|
(require 'ox-rss)
|
||||||
|
(require 'subr-x)
|
||||||
|
|
||||||
|
(defun publish-calculate-reading-time (buffer)
|
||||||
|
"Calculate the amount of minutes it would take to read the contents of BUFFER."
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(max 1 (/ (count-words (point-min) (point-max)) 228))))
|
||||||
|
|
||||||
|
(defun publish-format-reading-time (time)
|
||||||
|
"Return a string describing TIME."
|
||||||
|
(format "%d minute%s"
|
||||||
|
time
|
||||||
|
(if (= time 1) "" "s")))
|
||||||
|
|
||||||
|
(defun publish-org-sitemap (title list)
|
||||||
|
"Create a site map file. TITLE is used as the title, LIST is turned into a subtree."
|
||||||
|
(concat "#+TITLE: " title "\n"
|
||||||
|
"#+OPTIONS: toc:nil num:nil\n\n"
|
||||||
|
;; (message "Lets see here: %S" list)
|
||||||
|
(org-list-to-subtree list)))
|
||||||
|
|
||||||
|
(defun publish-org-sitemap-format-entry (entry style project)
|
||||||
|
"Format ENTRY as a healine.
|
||||||
|
STYLE is ignored and PROJECT is passed on directly to related functions."
|
||||||
|
(unless (directory-name-p entry)
|
||||||
|
(format "%s\n :PROPERTIES:\n :ID: %s\n :RSS_PERMALINK: %s\n :PUBDATE: %s\n :END:\n %s\n Published on: %s\n\n [[file:%s][Read More]] (%s)"
|
||||||
|
(org-publish-find-title entry project)
|
||||||
|
entry
|
||||||
|
(concat (string-remove-suffix ".org" entry) ".html")
|
||||||
|
(format-time-string
|
||||||
|
(cdr org-time-stamp-formats)
|
||||||
|
(org-publish-find-date entry project))
|
||||||
|
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents (concat (plist-get (cdr project) :base-directory) "/" entry))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(let ((current-element (org-element-at-point)))
|
||||||
|
(while (not (equal (org-element-type current-element) 'paragraph))
|
||||||
|
(org-forward-element)
|
||||||
|
(setq current-element (org-element-at-point)))
|
||||||
|
(buffer-substring-no-properties
|
||||||
|
(plist-get (cadr current-element) :contents-begin)
|
||||||
|
(plist-get (cadr current-element) :contents-end))))
|
||||||
|
(format-time-string
|
||||||
|
(cdr org-time-stamp-formats)
|
||||||
|
(org-publish-find-date entry project))
|
||||||
|
entry
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents (concat (plist-get (cdr project) :base-directory) "/" entry))
|
||||||
|
(publish-format-reading-time
|
||||||
|
(publish-calculate-reading-time (current-buffer)))))))
|
||||||
|
|
||||||
|
(setq org-rss-use-entry-url-as-guid t)
|
||||||
|
|
||||||
|
(setq org-export-exclude-tags '("noexport" "draft"))
|
||||||
|
|
||||||
|
(setq org-publish-project-alist
|
||||||
|
'(("posts"
|
||||||
|
:base-directory "posts/"
|
||||||
|
:base-extension "org"
|
||||||
|
:publishing-directory "public/"
|
||||||
|
:recursive t
|
||||||
|
:publishing-function org-html-publish-to-html
|
||||||
|
:html-head "<link rel=\"stylesheet\" href=\"assets/css/main.css\" type=\"text/css\"/>"
|
||||||
|
:html-preamble (lambda (project)
|
||||||
|
(let ((buffer (find-file-noselect (buffer-file-name))))
|
||||||
|
(unless (string= "ryuslash.org"
|
||||||
|
(car (org-publish-find-property (buffer-file-name) :title project)))
|
||||||
|
(publish-format-reading-time
|
||||||
|
(publish-calculate-reading-time buffer)))))
|
||||||
|
:auto-sitemap t
|
||||||
|
:sitemap-filename "index.org"
|
||||||
|
:sitemap-title "ryuslash.org"
|
||||||
|
:sitemap-format-entry publish-org-sitemap-format-entry
|
||||||
|
:sitemap-style list
|
||||||
|
:sitemap-function publish-org-sitemap
|
||||||
|
:sitemap-sort-files anti-chronologically)
|
||||||
|
("rss"
|
||||||
|
:base-directory "posts/"
|
||||||
|
:base-extension "org"
|
||||||
|
:html-link-home "https://ryuslash.org/"
|
||||||
|
:rss-link-home "https://ryuslash.org/"
|
||||||
|
:html-link-use-abs-url t
|
||||||
|
:rss-extension "xml"
|
||||||
|
:publishing-directory "public"
|
||||||
|
:publishing-function (org-rss-publish-to-rss)
|
||||||
|
:section-number nil
|
||||||
|
:exclude ".*"
|
||||||
|
:include ("index.org")
|
||||||
|
:table-of-contents nil)
|
||||||
|
("all" :components ("posts" "rss"))))
|
||||||
|
|
||||||
|
(provide 'publish)
|
||||||
|
;;; publish.el ends here
|
Loading…
Reference in a new issue