From 6e368141cbc2ecf1c450eae89a821ce7a864ccca Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sun, 23 Feb 2020 20:23:42 -0800 Subject: [PATCH] Dynamically generate the index file --- index.org | 20 ++++---------- posts/a-very-important-blog-post.org | 5 ++++ posts/my-new-emacs-configuration.org | 6 ++++ posts/new-blog.org | 10 +++++++ project-config.el | 41 +++++++++++++++++++++++++++- src/less/main.less | 7 +++++ 6 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 posts/a-very-important-blog-post.org create mode 100644 posts/my-new-emacs-configuration.org create mode 100644 posts/new-blog.org diff --git a/index.org b/index.org index 2a23de0..aae7b13 100644 --- a/index.org +++ b/index.org @@ -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: diff --git a/posts/a-very-important-blog-post.org b/posts/a-very-important-blog-post.org new file mode 100644 index 0000000..df9609e --- /dev/null +++ b/posts/a-very-important-blog-post.org @@ -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. diff --git a/posts/my-new-emacs-configuration.org b/posts/my-new-emacs-configuration.org new file mode 100644 index 0000000..7eef7b1 --- /dev/null +++ b/posts/my-new-emacs-configuration.org @@ -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. diff --git a/posts/new-blog.org b/posts/new-blog.org new file mode 100644 index 0000000..581d525 --- /dev/null +++ b/posts/new-blog.org @@ -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. diff --git a/project-config.el b/project-config.el index 4a9447b..944313e 100644 --- a/project-config.el +++ b/project-config.el @@ -10,7 +10,10 @@ :exclude "\\`README.org\\'" :base-extension "org" :publishing-function org-html-publish-to-html - :html-head "") + :html-head "" + :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)))))) diff --git a/src/less/main.less b/src/less/main.less index 1d5d8aa..828bc8b 100644 --- a/src/less/main.less +++ b/src/less/main.less @@ -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; +}