Skip to content

drym3r/org2nikola

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

org2nikola (v0.1.4)

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

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)
    ;; 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))
    (setq cmd "cd ~/projs/redguardtoo.github.io;git add .;git commit -m 'updated';git push origin master;git push gitcafe gitcafe-pages:refs/heads/master")
    (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.
  • Gitcafe is a different repository as the backup. You can remove it.

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"))
        (password "yourpassword")
        (username "yourusername")
        dir
        file
        lines
        rlt
        res
        cmd)
    (kill-new url)
    (message "%s => kill-ring" url)
    (setq rlt (shell-command-to-string (format "cd %s; nikola build" nikola-dir)))
    (setq lines (split-string rlt "\n"))
    (dolist (l lines)
      (when (string-match "output\\(.*/\\)*\\([^/]*\\)$" l)
        (setq dir (match-string 1 l))
        (setq file (match-string 2 l))
        (setq cmd (format "ncftpput -b -u %s -p %s ftp.yourdomain.net /blog%s %s/output%s%s"
                          username password 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.

Tag the post

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

Re-render all published posts

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

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

About

export org into html used by static blog generator like https://github.com/getnikola/nikola

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Emacs Lisp 99.7%
  • Shell 0.3%