📌 置頂: 請把任何比你弱勢的用路人當作你的至親對待。跟前車保持安全車距 (2秒以上)。

Using org2blog to publish Org-mode/Org-roam notes

In

Tags:



by

1. Why I want to do this?

I am using Org-mode and Org-roam to take notes, and sometimes I want to share the notes with people, exporting them as HTML should be a reasonable way to achieve that. The result of default Org-mode HTML publish looks fine for me, I like their headline numbering output, and I am also seeking about how to prettify Org-mode HTML result with CSS, it looks fantastic to me.

The only problem is – as you can see – I am blogging on WordPress, but not a static site, and this increase the cost of publishing new note to my blog. Copy and paste each note and manually adjust for code blocks? This will definitely put me off from either taking notes or publishing them.

2. Use org2blog to publish Org-mode notes to WordPress

Gladly, we have org2blog to publish Org-mode notes to WordPress! It is pretty easy and straight forward to use org2blog!

2.1. Setup org2blog

First, install it:

(use-package org2blog
  :ensure t)

And setup blog connection:

(setq org2blog/wp-blog-alist
      '(("myblog"
         :url "https://<your-wonderful-wordpress-url>/xmlrpc.php"
         :username "username")))
(setq org2blog/wp-show-post-in-browser 'show)

I also setup org2blog/wp-show-post-in-browser to show, so that each time I update the note to WordPress it will open up the post in browser for me.

2.2. Login to your WordPress

Use M-x org2blog-user-interface to open the org2blog main menu, then press 4 to enter password in minibuffer to login.

2.3. Upload note as a draft

Open up the main menu, and press j (Save Post Draft).

Done! It should now open up a browser and show you the draft in the tab.

3. Tricks and Hacks for org2blog

3.1. Export settings for headline section numbers (and TOC, TODO…etc)

I want section numbers in my notes, just like what Org-mode export has, but org2blog default to disable section numbers. We can use OPIONTS keyword to control export settings.

For example, if I want to have section numbers in my notes, then I can have the following keyword in my note:

#+OPTIONS: num:t

If I want multiple options, use space to separate them:

#+OPTIONS: num:t toc:t

3.2. Make org2blog properties insert after Org-roam

When publishing new draft or post, org2blog will insert their properties at the top of the file, this makes Org-roam feels bad (Org-roam‘s :PROPERTIES: should be at the top of the file).

We can apply the following patch to make org2blog insert their properties after Org-roam properties:

From 1fe31a575c6b1545588a6ea264c4bcd0e3d53e52 Mon Sep 17 00:00:00 2001
From: Louie Lu <[email protected]>
Date: Wed, 12 Jul 2023 10:34:20 -0400
Subject: [PATCH 1/2] Insert properties after org-roam properties

---
 org2blog.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/org2blog.el b/org2blog.el
index 6606d84..3184982 100755
--- a/org2blog.el
+++ b/org2blog.el
@@ -1818,6 +1818,8 @@ Legend:
                   (format "%s" err)))))
             (when from-buffer
               (goto-char (point-min))
+              (org-roam-end-of-meta-data t)
+              (previous-line)
               (when to-post (insert (concat "#+BLOG: " org2blog-blog-key "\n")))
               (insert (concat "#+POSTID: " post-id "\n")))
             (when from-subtree
@@ -2981,6 +2983,8 @@ Legend:
           (if subtree-p
               (org-entry-put (point) "POST_DATE" current-time)
             (goto-char (point-min))
+            (org-roam-end-of-meta-data t)
+            (previous-line)
             (insert (concat "#+DATE: " current-time "\n"))))
         current-time)))

--
2.41.0

3.3. Make org2blog to use filetags as TAGS

Apply the following patch, so org2blog will use #+filetags as #+TAGS for the WordPress post tags.

From 8e04318210ae55b3315576445ea70d9c77f35dfc Mon Sep 17 00:00:00 2001
From: Louie Lu <[email protected]>
Date: Wed, 12 Jul 2023 10:41:23 -0400
Subject: [PATCH 2/2] Use filetags as TAGS

---
 org2blog.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/org2blog.el b/org2blog.el
index 3184982..9205bd2 100755
--- a/org2blog.el
+++ b/org2blog.el
@@ -3005,8 +3005,8 @@ Legend:
          (cons "title" (org2blog--bprop "TITLE"))
          (cons "description" nil)
          (cons "tags"
-               (split-string (or (org2blog--bprop "TAGS") "")
-                             "\\( *, *\\)" t))
+               (split-string (or (org2blog--bprop "filetags") "")
+                             "\\( *: *\\)" t))
          (cons "categories"
                (split-string (or (org2blog--bprop "CATEGORY") "")
                              "\\( *, *\\)" t))
--
2.41.0

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.