Home Blog RSS

The setup of my Blog

Taken directly from my configuration, as I think that this deserves a separate blog post.

My workflow for blogging is following:

  1. Create a new blog post as a org file with #+TITLE and #+DATE.
  2. Assign a #+CATEGORY to it, so that the sitemap can be generated.
  3. Write what you want.
  4. Run my-blog-publish which
    • exports the contents to html file and
    • generates RSS using webfeeder.
  5. After that push the pages to the public git repository and post an update on Mastodon.

Install needed packages.

(require 'ox-publish)
(use-package webfeeder
  :ensure t)
(use-package htmlize
  :ensure t)
(load "~/myorg/config/lisp/emacstodon.el") ; From https://github.com/igb/emacstodon.

Helper functions.

(defun my-org-find-category (file)
  "Find #CATEGORY in the posts."
  (with-temp-buffer
    (message file)
    (insert-file-contents file)
    (goto-char (point-min))
    (let ((beg (+ 1 (re-search-forward "^#\\+CATEGORY\:")))
          (end (progn (forward-word) (point))))
      (buffer-substring beg end))))

(defun my-sitemap-format-entry (entry style project)
  "Format the entries in the sitemap."
  (format "%s - [[file:%s][%s]] (%s)"
          (format-time-string "%Y-%m-%d" (org-publish-find-date entry project))
          entry
          (org-publish-find-title entry project)
          (concat "#" (my-org-find-category
           (expand-file-name entry (plist-get (cdr project) :base-directory))))))

(defun my-rss-gen()
  "Generate an RSS feed."
  (webfeeder-build
   "rss.xml"
   "~/myorg/blog/pages/"
   "https://anonimno.codeberg.page/"
   (delete '"blog.html" (directory-files "~/myorg/blog/pages/" nil
                                          "\.html"))
   :title "anonimno's blog"
   :description "My blog in RSS"
   :builder 'webfeeder-make-rss))

  (defun my-blog-publish()
    "Publish the blog, update RSS and post an update on Mastodon."
    (interactive)
    (progn
      (org-publish-all)
      (my-rss-gen)
      (save-excursion
        (dired "~/myorg/blog/pages/")
        (magit-status))
      (with-temp-buffer
          (insert "New post available on my blog, go and have a look 🥸! https://anonimno.codeberg.page/blog.html ") ; Post on Mastodon.
          (toot))))

Setup for org-publish.

(setq org-publish-project-alist
      '(("blog"
         :base-directory "~/myorg/blog/src/posts/"
         :base-extension "org"
         :publishing-directory "~/myorg/blog/pages/"
         :publishing-function org-html-publish-to-html
         :recursive t
         :exclude "level-.*\\|.*\.draft\.org"
         :auto-sitemap t
         :sitemap-filename "blog.org"
         :sitemap-title "Posts"
         :sitemap-sort-files anti-chronologically
         :sitemap-style list
         :sitemap-format-entry my-sitemap-format-entry
         :html-head-include-default-style nil
         :html-head "<link rel=\"stylesheet\" type=\"text/css\" href=\"assets/orgbasic.css\" />"
         :html-preamble "<p><span class=\"date\" style=\"float: left;\"> <a href= \"/index.html\">Home</a></span> <span style=\"float: center;\"><a href= \"/blog.html\">Blog</a></span> <span style=\"float: right;\"><a href= \"/rss.xml\">RSS</a></span></p>"
         :html-postamble "<p><span class=\"date\" style=\"float: left;\"> <a href= \"https://creativecommons.org/licenses/by-sa/4.0/\">CC BY-SA 4.0</a></span> <span style=\"float: center;\"><a href= \"mailto:anonimno@mailbox.org\">Contact</a></span> <span style=\"float: right;\"><a href= \"https://social.tchncs.de/@anonimno\">Discuss</a></span></p>")

        ("assets"
         :base-directory "~/myorg/blog/src/assets/"
         :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|webp"
         :publishing-directory "~/myorg/blog/pages/assets/"
         :recursive t
         :publishing-function org-publish-attachment)

        ("all" :components ("blog" "assets"))))

CC BY-SA 4.0 Contact Discuss