Dynamically generate the index file

This commit is contained in:
Tom Willemse 2020-02-23 20:23:42 -08:00
parent cbee86f26d
commit 6e368141cb
6 changed files with 73 additions and 16 deletions

View file

@ -1,19 +1,9 @@
#+TITLE: ryuslash.org
#+STARTUP: showall
#+OPTIONS: toc:nil num:nil
#+HTML_LINK_UP:
#+HTML_LINK_HOME: https://ryuslash.org/
* My new Emacs configuration :draft:
:PROPERTIES:
:ID: 0069eced-52ed-4cb2-bb75-78e7ea32bd6c
:PUBDATE: <2019-10-06 Sun 18:18>
:END:
#+BEGIN: blog-posts
I'm still working on this one.
* New blog
:PROPERTIES:
:ID: 68c55701-d8ce-44a1-9c97-6c16cf34890c
:PUBDATE: <2019-10-06 Sun 12:55>
:END:
It's that time again... I've started a new project to build and maintain my
site and of course it has to come with a new blog post.
#+END:

View file

@ -0,0 +1,5 @@
#+TITLE: A very important blog post
#+ID: a-very-important-blog-post
#+PUBDATE: <2020-02-23 Sun 18:28>
Very important business here.

View file

@ -0,0 +1,6 @@
#+TITLE: My new Emacs configuration
#+ID: my-new-emacs-configuration
#+PUBDATE: <2019-10-06 Sun 18:18>
#+TAGS: draft
I'm still working on this one.

10
posts/new-blog.org Normal file
View file

@ -0,0 +1,10 @@
#+TITLE: New Blog
#+ID: new-blog
#+PUBDATE: <2019-10-06 Sun 12:55>
#+READING_TIME: 6s
It's that time again... I've started a new project to build and maintain my site
and of course it has to come with a new blog post. I'm trying to have it
generate an index based on the files in this directory.
I don't want it to include anything beyond the first paragraph, though.

View file

@ -10,7 +10,10 @@
: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-head "<link rel=\"stylesheet\" href=\"assets/css/main.css\" type=\"text/css\"/>"
:html-link-home "https://ryuslash.gitlab.io/ryuslash.org/"
:html-link-user-abs-url t
:recursive t)
("ryuslash-rss"
:base-directory "."
:publishing-directory "public_html"
@ -20,4 +23,40 @@
: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 (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-element (filename alist)
(format "* %s\n :PROPERTIES:\n :ID: %s\n :PUBDATE: %s\n :END:\n\n %s\n[[file:%s][Read more]]\n"
(alist-get "TITLE" alist nil nil #'equal)
(alist-get "ID" alist nil nil #'equal)
(alist-get "PUBDATE" alist nil nil #'equal)
(alist-get "BODY" alist nil nil #'equal)
filename))
(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 (lambda (file) (project-config-print-element (concat "posts/" file) (project-config-parse-document (concat "posts/" file))))
files))))))

View file

@ -1,12 +1,19 @@
@background-color: #111114;
@foreground-color: #bfbfbf;
@link-color: #a88654;
@font-family: sans-serif;
body {
background-color: @background-color;
color: @foreground-color;
font-family: @font-family;
}
a {
color: @link-color;
}
#content {
max-width: 900px;
margin: 0 auto;
}