Skip to content

Latest commit

 

History

History
122 lines (101 loc) · 5.54 KB

README.org

File metadata and controls

122 lines (101 loc) · 5.54 KB

org2nikola

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.

Screenshot: https://raw.githubusercontent.com/redguardtoo/org2nikola/master/screenshots/org2nikola-demo-nq8.png

Install

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")

Usage

Render HTML

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.

Tag the post

It’s org-mode feature. Press C-c C-c or M-x org-ctrl-c-ctrl-c.

Re-render all published posts

Run M-x org2nikola-rerender-published-posts.

Please provide the directory containing org files if it’s not set in org2nikola-org-blog-directory.

Nikola setup

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+.

Tips

Customize html output

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)

Upload HTML (OPTIONAL)

You can always upload HTML files manually to the web server. Org2nikola provides org2nikola-after-hook for automation.

GitHub Pages

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.

FTP

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.

Credits

Bug report

https://github.com/redguardtoo/org2nikola

License

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/.