Update reading time generation

This commit is contained in:
Tom Willemse 2020-02-25 23:32:48 -08:00
parent 9bdcc27549
commit 10cf6bbc49
5 changed files with 13 additions and 7 deletions

View file

@ -1,5 +1,4 @@
#+TITLE: A very important blog post #+TITLE: A very important blog post
#+SUBTITLE: Reading time: 0 minutes
#+ID: a-very-important-blog-post #+ID: a-very-important-blog-post
#+PUBDATE: <2020-02-23 Sun 18:28> #+PUBDATE: <2020-02-23 Sun 18:28>

View file

@ -1,5 +1,4 @@
#+TITLE: My new Emacs configuration #+TITLE: My new Emacs configuration
#+SUBTITLE: Reading time: 0 minutes
#+ID: my-new-emacs-configuration #+ID: my-new-emacs-configuration
#+PUBDATE: <2019-10-06 Sun 18:18> #+PUBDATE: <2019-10-06 Sun 18:18>
#+TAGS: draft #+TAGS: draft

View file

@ -1,5 +1,4 @@
#+TITLE: New Blog #+TITLE: New Blog
#+SUBTITLE: Reading time: 4 minutes
#+ID: new-blog #+ID: new-blog
#+PUBDATE: <2019-10-06 Sun 12:55> #+PUBDATE: <2019-10-06 Sun 12:55>

View file

@ -1,5 +1,4 @@
#+TITLE: Making docker-compose easier with wdocker #+TITLE: Making docker-compose easier with wdocker
#+SUBTITLE: Reading time: 3 minutes
#+PUBDATE: <2016-02-21> #+PUBDATE: <2016-02-21>
#+FILE_TAGS: wdocker docker docker-compose #+FILE_TAGS: wdocker docker docker-compose
#+OPTIONS: num:nil toc:nil #+OPTIONS: num:nil toc:nil

View file

@ -12,6 +12,7 @@
:publishing-function org-html-publish-to-html :publishing-function org-html-publish-to-html
:html-head "<link rel=\"stylesheet\" href=\"assets/css/main.css\" type=\"text/css\"/>" :html-head "<link rel=\"stylesheet\" href=\"assets/css/main.css\" type=\"text/css\"/>"
:html-link-home "https://ryuslash.gitlab.io/ryuslash.org/" :html-link-home "https://ryuslash.gitlab.io/ryuslash.org/"
:html-link-up nil
:html-link-user-abs-url t) :html-link-user-abs-url t)
("ryuslash.org Posts" ("ryuslash.org Posts"
:base-directory "posts" :base-directory "posts"
@ -21,7 +22,11 @@
:publishing-function org-html-publish-to-html :publishing-function org-html-publish-to-html
:html-head "<link rel=\"stylesheet\" href=\"../assets/css/main.css\" type=\"text/css\"/>" :html-head "<link rel=\"stylesheet\" href=\"../assets/css/main.css\" type=\"text/css\"/>"
:html-link-home "https://ryuslash.gitlab.io/ryuslash.org/" :html-link-home "https://ryuslash.gitlab.io/ryuslash.org/"
:html-link-user-abs-url t) :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" ("ryuslash-rss"
:base-directory "." :base-directory "."
:publishing-directory "public_html" :publishing-directory "public_html"
@ -56,14 +61,19 @@
(org-forward-element)) (org-forward-element))
alist))) alist)))
(defun project-config-print-reading-time (time)
(format "%d minute%s"
time
(if (= time 1) "" "s")))
(defun project-config-print-element (alist) (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 (%d minutes)]]\n" (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 'TITLE alist)
(alist-get 'ID alist) (alist-get 'ID alist)
(alist-get 'PUBDATE alist) (alist-get 'PUBDATE alist)
(alist-get 'BODY alist) (alist-get 'BODY alist)
(alist-get 'NAME alist) (alist-get 'NAME alist)
(alist-get 'LENGTH alist))) (project-config-print-reading-time (alist-get 'LENGTH alist))))
(defun project-config-reading-time (file) (defun project-config-reading-time (file)
(with-current-buffer (find-file file) (with-current-buffer (find-file file)