Mdk-Memo

Writing Blog with org-mode

[2018-09-14 Fri]

Your Life in Plain Text

This blog is written in org-mode.

Org-mode is a strucutred text format like markdown. Org-mode and Emacs make our writing environment very confortable.

Emacs also has a exporting feature that publishes many format including pdf, latex and html. Emacs supports site-map feature so that we can export static site with articles and an index.html by one command.

Actually, there are many writers who love org-mode. And they heavily customize org-mode with elisp.

Painful elisp

Despite, learning and writing elisp is quite painful.

Org-mode seems to be written in elisp. We have to customize it with elisp. Elisp is too much hard to learn to just customize personal blog.

I gave up.

Frameworks

There are many frameworks to generate static blogs:

Some use these frameworks to export orgs.

They cover what I want to do. But I felt they are too much to build my small personal blog. Who wants to kick a web server to preview articles?

Ruby

I love ruby and rails. This is simple and painless solution for me because ruby has many libraries to process texts and htmls.

ERB

Ruby has an erb template engine.

I inserted HTML files from org to templates. It is quite easy way.

org-ruby

Org-ruby is a library for ruby to parse and export orgs. I cant insert some ids and classes into generated HTML to customize apearances and behaviors while parsing org files.

Codes

These are conceptual pseudocode samples.

Erb templtes should be like this:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <title>YOUR TITLE</title>
  </head>
  
  <body>
    <HEADER>
      <H1 class="title"> BLOG TITLE </H1>
    </HEADER>
    <article id="main-article">
      <%= @html %>
    </article>
  </body>
</html>

@html is a strings which contains html code. Ruby generate @html like this:

data = IO.read(filename)
@html = Orgmode::Parser.new(data, { markup_file: "html.tags.yml" })
          .to_html
          .split("\n").map { |line|
             # processing
             line = some_process line
             line
           }.join("\n")

Conclusion

Finally, I’ve wrote blog form scratch. so I understand every inch of my scripts. If I want some features, I code. That’s simple. That’s how programmers should be.

I’ve not uploaded codes to github or any repositories. My blogging scripts quite dependent on my system. I have to generalize it to publish it.