Convert Org into HTML used by static blog generator nikola.
Features:
- URL is normalized into pinyin if article title is Chinese
- Support 3rd party syntax highlighter JS library like highlight.js
- local image supported
Here is my blog created by org2nikola.
Download org2nikola.el and put it somewhere, say “~/.emacs.d/lisp/nikola”.
Insert below code into ~/.emacs:
(add-to-list 'load-path "~/.emacs.d/lisp/nikola") (require 'org2nikola) ;; OPTIONAL, set the root directory of nikola ;; "~/.config/nikola/posts" contains the *.meta and *.wp (setq org2nikola-output-root-directory "~/.config/nikola")
Say I got a org file with following content:
* article 1
blah
* article 2
blah blah
Put focus in inside of subtree “article 2” and M-x org2nikola-export-subtree
. That’s it.
Org2nikola output files into “~/.config/nikola”. You need run cd ~/.config/nikola && nikola build
to render website.
You need run M-x org2nikola-rerender-published-posts
once when you switch computer to publish blog.
It’s org-mode
feature. Press C-c C-c
or M-x org-ctrl-c-ctrl-c
.
Run M-x org2nikola-rerender-published-posts
.
Please provide the directory containing org files if it’s not set in org2nikola-org-blog-directory
.
Check my conf.py. Google Analytics and hightlight.js (syntax highlight JS library) is used.
If you are a newbie of Nikola or you need import post from wordpress, check this guide.
You may (setq org2nikola-use-verbose-metadata t)
because more verbose meta data format is suggested by nikola 7.7+.
You can use org2nikola-process-output-html-function
to customize the html,
(defun my-customize-post-content (html title post-slug)
(ignore title post-slug)
html)
(setq org2nikola-process-output-html-function 'my-customize-post-content)
You can always upload HTML files manually to the web server. Org2nikola provides org2nikola-after-hook
for automation.
Here is the sample setup:
(defun org2nikola-after-hook-setup (title slug)
"see https://help.github.com/articles/setting-up-a-custom-domain-with-github-pages/ for setup
run `ln -s ~/projs/redguardtoo.github.io ~/.config/nikola/output`, btw"
(let* ((url (concat "http://blog.binchen.org/posts/" slug ".html"))
(nikola-dir (file-truename "~/.config/nikola"))
(cmd "cd ~/projs/redguardtoo.github.io && git add . && git commit -m updated && git push origin master"))
;; copy the blog url into kill-ring
(kill-new url)
(message "%s => kill-ring" url)
;; nikola is building posts ...
(shell-command (format "cd %s; nikola build" nikola-dir))
(shell-command cmd)))
(add-hook 'org2nikola-after-hook 'org2nikola-after-hook-setup)
Please note my user name at github is “redguardtoo” and my blog domain is “blog.binchen.org”. You need replace them with your own stuff.
Here is the setup:
(defun org2nikola-after-hook-setup (title slug)
(let* ((url (concat "http://blog.yourdomain.net/posts/" slug ".html"))
(nikola-dir (file-truename "~/.config/nikola"))
(lines (split-string (shell-command-to-string (format "cd %s; nikola build" nikola-dir)) "\n")))
(kill-new url)
(message "%s => kill-ring" url)
(dolist (l lines)
(when (string-match "output\\(.*/\\)*\\([^/]*\\)$" l)
(let* ((dir (match-string 1 l))
(file (match-string 2 l))
(cmd (format "ncftpput -b -u %s -p %s ftp.yourdomain.net /blog%s %s/output%s%s"
"yourusername"
"yourpassword"
dir
nikola-dir
dir
file)))
(shell-command cmd))))))
(add-hook 'org2nikola-after-hook 'org2nikola-after-hook-setup)
You need install ncftp which is the FTP client. See How a programmer publish static HTML blog in Emacs for details.
- Puneeth Chaganti (AKA punchagan) I borrow many ideas from his project org2blog.
https://github.com/redguardtoo/org2nikola
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.