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:
|
1 2 |
(<span style=“color: #c48702; font-weight: bold;”>use–package</span> <span style=“color: #64aa0f;”>org2blog</span> <span style=“color: #ff7a7f; font-weight: bold;”>:ensure</span> t) |
And setup blog connection:
|
1 2 3 4 5 |
(<span style=“color: #c48702; font-weight: bold;”>setq</span> org2blog/wp–blog–alist ‘((<span style=”color: #f06a3f;”>”myblog”</span> <span style=”color: #ff7a7f; font-weight: bold;”>:url</span> <span style=”color: #f06a3f;”>”https://<your-wonderful-wordpress-url>/xmlrpc.php”</span> <span style=”color: #ff7a7f; font-weight: bold;”>:username</span> <span style=”color: #f06a3f;”>”username”</span>))) (<span style=”color: #c48702; font-weight: bold;”>setq</span> 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:
|
1 |
<span style=“color: #887c8a;”>#+OPTIONS: num:t</span> |
If I want multiple options, use space to separate them:
|
1 |
<span style=“color: #887c8a;”>#+OPTIONS: num:t toc:t</span> |
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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
From 1fe31a575c6b1545588a6ea264c4bcd0e3d53e52 Mon Sep 17 00:00:00 2001 From: Louie Lu <a href=“mailto:git%40louie.lu”><git@louie.lu></a> Date: Wed, 12 Jul 2023 10:34:20 –0400 Subject: [PATCH 1/2] Insert properties after org–roam properties <span style=“background-color: #36322f; font-weight: bold;”>—–</span> org2blog.el | 4 ++++ 1 file changed, 4 insertions(+) diff —git a/org2blog.el b/org2blog.el index 6606d84..3184982 100755 —– <span style=“font-weight: bold;”>a/org2blog.el</span> +++ <span style=“font-weight: bold;”>b/org2blog.el</span> <span style=“background-color: #36322f; font-weight: bold;”>@@ –1818,6 +1818,8 @@</span><span style=“background-color: #36322f;”> Legend:</span> (format “%s” err))))) (when from–buffer (goto–char (point–min)) <span style=“color: #a0e0a0; background-color: #17360f;”>+</span><span style=“color: #a0e0a0; background-color: #17360f;”> (org–roam–end–of–meta–data t)</span> <span style=“color: #a0e0a0; background-color: #17360f;”>+</span><span style=“color: #a0e0a0; background-color: #17360f;”> (previous–line)</span> (when to–post (insert (concat “#+BLOG: “ org2blog–blog–key “\n”))) (insert (concat “#+POSTID: “ post–id “\n”))) (when from–subtree <span style=“background-color: #36322f; font-weight: bold;”>@@ –2981,6 +2983,8 @@</span><span style=“background-color: #36322f;”> Legend:</span> (if subtree–p (org–entry–put (point) “POST_DATE” current–time) (goto–char (point–min)) <span style=“color: #a0e0a0; background-color: #17360f;”>+</span><span style=“color: #a0e0a0; background-color: #17360f;”> (org–roam–end–of–meta–data t)</span> <span style=“color: #a0e0a0; background-color: #17360f;”>+</span><span style=“color: #a0e0a0; background-color: #17360f;”> (previous–line)</span> (insert (concat “#+DATE: “ current–time “\n”)))) current–time))) <span style=“color: #ffbfbf; background-color: #4b120a;”>–</span><span style=“color: #ffbfbf; background-color: #4b120a;”>–</span> 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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
From 8e04318210ae55b3315576445ea70d9c77f35dfc Mon Sep 17 00:00:00 2001 From: Louie Lu <a href=“mailto:git%40louie.lu”><git@louie.lu></a> Date: Wed, 12 Jul 2023 10:41:23 –0400 Subject: [PATCH 2/2] Use filetags as TAGS <span style=“background-color: #36322f; font-weight: bold;”>—–</span> org2blog.el | 4 ++— 1 file changed, 2 insertions(+), 2 deletions(–) diff —git a/org2blog.el b/org2blog.el index 3184982..9205bd2 100755 —– <span style=“font-weight: bold;”>a/org2blog.el</span> +++ <span style=“font-weight: bold;”>b/org2blog.el</span> <span style=“background-color: #36322f; font-weight: bold;”>@@ –3005,8 +3005,8 @@</span><span style=“background-color: #36322f;”> Legend:</span> (cons “title” (org2blog—bprop “TITLE”)) (cons “description” nil) (cons “tags” <span style=“color: #ffbfbf; background-color: #4b120a;”>–</span><span style=“color: #ffbfbf; background-color: #4b120a;”> (split–string (or (org2blog—bprop “</span><span style=”color: #ffbfbf; background-color: #6f1a16;”>TAGS</span><span style=”color: #ffbfbf; background-color: #4b120a;”>”) “”)</span> <span style=“color: #ffbfbf; background-color: #4b120a;”>–</span><span style=“color: #ffbfbf; background-color: #4b120a;”> “\\( *</span><span style=“color: #ffbfbf; background-color: #6f1a16;”>,</span><span style=“color: #ffbfbf; background-color: #4b120a;”> *\\)“ t))</span> <span style=“color: #a0e0a0; background-color: #17360f;”>+</span><span style=“color: #a0e0a0; background-color: #17360f;”> (split–string (or (org2blog—bprop “</span><span style=”color: #a0e0a0; background-color: #204810;”>filetags</span><span style=”color: #a0e0a0; background-color: #17360f;”>”) “”)</span> <span style=“color: #a0e0a0; background-color: #17360f;”>+</span><span style=“color: #a0e0a0; background-color: #17360f;”> “\\( *</span><span style=“color: #a0e0a0; background-color: #204810;”>:</span><span style=“color: #a0e0a0; background-color: #17360f;”> *\\)“ t))</span> (cons “categories” (split–string (or (org2blog—bprop “CATEGORY”) “”) “\\( *, *\\)“ t)) <span style=“color: #ffbfbf; background-color: #4b120a;”>–</span><span style=“color: #ffbfbf; background-color: #4b120a;”>–</span> 2.41.0 |
Leave a Reply