Write Hugo Posts with OrgMode and ox-hugo
2024-07-17
Why I want to write a blog?
Writing a blog is not the thing that most people would do. I have never thought of it, even though I get lots of valuable information from blogs written by other people. Such information cover various aspects, including courage if you encounter career crisis, curiosity when you find somebody else have tried something cool making live easier, or just simple happiness related to your life.
At the beginning, I wrote the blog for myself. It’s more accurate to call it “note” instead of “blog”. The notes contain the knowledge I learned from high-quality blogs, classic books and courses. The notes are well-(organized, categorized, and tagged), stored in folders, and can only be viewed in “folder” version if I havn’t used tools to generate a “website” version of them. Even though I generate a “website” version of these notes, I can treat them only for personal use and choose not to publish them.
My mind changed when I learned about GNU.
“As we enjoy great advantages from the inventions of others, we should be glad of an opportunity to serve others by any invention of ours, and this we should do freely and generously.” — Benjamin Franklin
I rethink the bad education experience I have been given by most of the teachers. Such education is cheap (has a price) and of low quality. I recall the few teachers who once told me the true knowledge (a priceless treasure) and helped me without hesitation when I felt down. They did so utterly out of their goodness and kindness, and this had nothing to do with the salary they got paid or something else. I start to use Emacs to:
- write R program with “Emacs + ess” instead of RStudio1/SublimeText
- write LaTex with “Emacs + auctex” instead of TeXstudio/WinEdt/SublimeText
- build blog with “Hugo + Emacs + OrgMode + ox-hugo” instead of “Hexo + SublimeText + Markdown”
I start to publish the notes on the blog. Two main reasons are as follows:
-
“How much you are willing to pay for the knowledge?”, “What’s the just and reasonable price for the knowledge?”, I have asked myself these kind of questions several times. My current answer is: it depends on what kind of knowledge we are discussed.
- If the knowledge is fundamental, it’s discovered several decades ago, and highly related to human’s normal happiness. It should be free.
- If the knowledge is at the forefront of academic, it’s should be priced justly and reasonablely by rational society.
- If the knowledge is in the middle of the above situation, I don’t know. But if we discover the knowledge, we should be humble and kind, as we are standing on the shoulders of giants.
What I post on blog is the fundamental knowledge I learned for free from other great blogs or websites. I try my best tidying them and expressing my own understanding. I hope somebody could find my post helpful when he meet the same problem I met before.
-
Writing blog is my way of participating in public life and breaking down the barriers of knowledge. Compared with writing posts on WeChat or ZhiHu, building personal blog has the highest flexibility and customization, thus is time-consuming at the beginning. To me, I already get a huge payoff of being able to write these posts.
For those who read the above content carefully, please forgive my poor writing. If you want to say something to me, feel free send an email to jwenfight@163.com.
OrgMode + ox-hugo
-
Org is included in distributions of GNU Emacs
Useful links: Hello Worg, the Org-Mode Community! => Org-mode Tutorials => Rainer König video tutorials
-
Install ox-hugo, adding the follows to config file
(with-eval-after-load 'ox (require 'ox-hugo))
Then we can play with the quick start of ox-hugo and these example org files.
Remark: org-publish-project-alist, learned from Rainer’s video, is a variable defined in ox-publish.el. We cannot
(require "ox-publish")
once we use ox-hugo. Otherwise, C-c C-e will not show the H option built in the ox-hugo pkg. -
Deal with unexpected spaces in Asian Language
If auto-fill-mode is on (insert new line when the number of characters in one line reach a limit), without any tweak, the following in org file
中午 吃啥
will lead to
中午 吃啥
in the Markdown file through ox-hugo export bindings, and become
<p>中午 吃啥</p>
in the HTML file exported by Blackfriday of Hugo, and end up with the ugly
中午 吃啥
with a white blank in the middle.
With the keyword setting:
#+hugo_locale: zh
the following in org file
中午 吃啥
will lead to
中午吃啥
in the Markdown file, and become
<p>中午吃啥</p>
in the HTML file, and end up with the beautiful
中午吃啥
BTW, I am so impressive that the author of ox-hugo once went to the Emacs China, the largest Emacs forum in China, and solved this issues.
Other references unrelated to “OrgMode + ox-hugo”
-
go-org kind of translates Org to HTML. Install it as follows: (my ~/bin is in the PATH, Ref)
git clone https://github.com/niklasfasching/go-org cd go-org go build . mv go-org ~/bin
-
The Asian Language issue also occurs in go-org and the solution is (Ref):
#+options: ealb:t
Line breaks between multi-byte characters are omitted when the ealb option is set.
The example is also insightful, east_asian_line_breaks in pandoc:
jwen@MacBook-Pro content-org % cat test.org 你 好 你好 Hello World jwen@MacBook-Pro content-org % pandoc -t html -o test.html test.org; cat test.html <p>你 好</p> <p>你好</p> <p>Hello World</p> jwen@MacBook-Pro content-org % pandoc -f org+east_asian_line_breaks -t html -o test.html test.org; cat test.html <p>你好</p> <p>你好</p> <p>Hello World</p> jwen@MacBook-Pro content-org % go-org render test.org html <p>你 好</p> <p> 你好</p> <p> Hello World</p> jwen@MacBook-Pro content-org % cat test.org #+options: ealb:t 你 好 你好 Hello World jwen@MacBook-Pro content-org % go-org render test.org html <p> 你好</p> <p> 你好</p> <p> Hello World</p>
-
What’s the relation between go-org (translates org to html) and C-c C-e h h? (todo)
-
Build blog with “Emacs + OrgMode + ox-publish”, an excellent video, another choice.
-
I hate RStudio. Let me quote two paragraphs from the great book Learn Python 3 the Hard Way, which I think is suitable for the beginner of any language:
-
“Anyone trying to hide knowledge from you, or worse, make you get it from them instead of through your own efforts, is trying to make you depend on them for your skills. Don’t listen to them, and do the exercises anyway so that you learn how to educate yourself.”
-
“Relying on an IDE means that you can’t work with new programming languages until some company decides to sell you an IDE for that language. This means you can’t use that new language until the language is large enough to justify a lucrative customer base. If you are confident you can work with only a programmer’s text editor (like Vim, Emacs, Atom, etc.) then you don’t have to wait for a third party. IDEs are nice in some situations (such as working with a giant existing code base) but being addicted to them will limit your future.”
-