Changed the blog engine to nikola
Table of Contents
It has been a while since the last time I updated my blog. I changed my blogging engine to nikola. Now my tool chain for writing is more streamlined, hopefully I post more frequently.
1 reStructuredText to org-mode
I do enjoy using one general tool for many tasks - I like having a consistent environment for different tasks. For example, I chose Python (a general purpose language) instead of domain specific languages such as R and MATLAB for my programming needs.
I have been looking for something like that for my writing as well, and since I used Python a lot, reStructuredText was a good candidate. With reStructuredText, I could generate output in multiple formats (html, pdf, slides), and I like the grammar.
With reStructuredText, I started using Emacs more for writing. Emacs'
rst-mode
is very well done, and I have been using org-mode for a while as
well, even though for a while I mainly used it for the TODO list management
and some outline generation only.
Then this year I started teaching, and I had multiple sections, and I started looking for ways to minimize the redundancy in course contents files. For example, syllabi for all sections of classes share many common parts and if I maintain separate files for each class, I have to modify all the files every time I make some changes on one of the common parts.
So I started writing lecture slides in reStructuredText in org-mode, putting
reStructuredText code in code blocks and using org-babel
to tangle the
source code into output files. In that way, I just write the common parts
once, and I could include them in multiple files. For slide generation, I used
hieroglyph package which was great. Also I liked that I can generate
document-style lecture note for distribution from the same source.
But quickly I started feeling that putting reStructuredText code inside code blocks cumbersome. In addition, I really missed the easy navigation of tree structure of org-mode. So I looked for a way to just use org-mode to write everything instead of putting reStructuredText code inside code-blocks.
Then I learned about org-export
which can export an org-mode document to
multiple output formats. Since then I started using org-mode to write my
course notes. I had to learn a few tricks and also install org 8.3beta, but
now the results has been very satisfactory. Now I write lecture note in
org-mode, , and use ox-beamer
to generate beamer slides for presentations,
and use ox-latex
to generate lecture notes from the same source. org-mode
is just a pleasure to use. Now I believe I found the tool-chain for all my
writing needs: Emacs and org-mode
.
2 nikola
Naturally I started searching for a blogging engine which enables me to use
org-mode. I have been using tinkerer for a while, and it is great, but there
are a couple of steps you have to go through to use org-mode to write
posts. Exporting a subtree to a .rst
file is easy, but there are some manual
steps involved - basically you have to add a new post to the sphinx index file
either by manually or by using tinkerer.
Then I found nikola. Unlike tinkerer, nikola automatically reads files in the
designated posts folder and generates index - so you don't have to manually
add anything to the index. In addition, there is a tool org2nikola which
generates a post from a org subtree, so I can put all my posts into one .org
file.
3 Setup
You need to add the .wp
file extensions to the POSTS
and PAGES
tuples,
and also to markdown compilers in your conf.py
:
POSTS = (
("posts/*.rst", "posts", "post.tmpl"),
("posts/*.txt", "posts", "post.tmpl"),
("posts/*.wp", "posts", "post.tmpl"),
)
PAGES = (
("stories/*.rst", "stories", "story.tmpl"),
("stories/*.txt", "stories", "story.tmpl"),
("stories/*.wp", "stories", "story.tmpl"),
)
COMPILERS = {
"rest": ('.rst', '.txt'),
"markdown": ('.md', '.mdown', '.markdown', '.wp'),
"textile": ('.textile',),
"txt2tags": ('.t2t',),
"bbcode": ('.bb',),
"wiki": ('.wiki',),
"ipynb": ('.ipynb',),
"html": ('.html', '.htm'),
# PHP files are rendered the usual way (i.e. with the full templates).
# The resulting files have .php extensions, making it possible to run
# them without reconfiguring your server to recognize them.
"php": ('.php',),
# Pandoc detects the input from the source filename
# but is disabled by default as it would conflict
# with many of the others.
# "pandoc": ('.rst', '.md', '.txt'),
}
3.1 Syntax Highlighting
To use highlight.js for syntax highlighting, add a definition of EXTRA_HEAD_DATA
:
EXTRA_HEAD_DATA = """
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/languages/lisp.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/languages/r.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
"""
As you can see, I added syntax highlighting for lisp
and r
in addition to
the defaults ones. You can change the theme from default
to others such as
solarized_light
.
4 How to use
Just call org2nikola-export-subtree
in the subtree that you want to export
as a nikola post. It will ask you where is the root directory for your nikola
blog. It seems it just uses the top level heading.
Comments
Comments powered by Disqus