Ox-Nikola exports your Org documents to Nikola posts in reStructuredText. Ox-Nikola depends on Ox-Rst and relies on the Org-mode 8.0 export framework.
Add the following in your init.el
(require 'ox-nikola)
ox-nikola
export back-end generates nikola blog posts
in reStructuredText syntax for an Org mode buffer.
To export your org document to, press C-c C-e
, and then n
.
Export as a text file written in reStructured syntax.
For an Org file, post.org
, the resulting file will be post.rst
.
The file will be overwritten without warning.
Export as a temporary buffer. Do not create a file.
Org:
#+TITLE: This is the title of the document #+AUTHOR: Author #+EMAIL: mailaddress@example.com #+DATE: 2013/12/31 00:00 #+DESCRIPTION: description text #+KEYWORDS: tag1, tag2 #+OPTIONS: author:nil #+NIKOLA_TYPE: text
reStructuredText:
.. title: This is the title of the document
.. slug: This-is-the-title-of-the-document
.. date: 2013/12/31 00:00
.. tags: tag1, tag2
.. link:
.. description: description text
.. type: text
Org:
#+NIKOLA_UPDATED: 2015/08/30
reStructuredText:
.. updated: 2015/08/30
Org:
#+TITLE: This is the title of the document #+NIKOLA_SLUG: slug-for-nikola
reStructuredText:
.. title: This is the title of the document
.. nikola: slug-for-nikola
Org:
#+KEYWORDS: tag1, tag2
reStructuredText:
.. tags: tag1, tag2
Org:
#+NIKOLA_SECTION: section
reStructuredText:
.. section: section
Org:
#+NIKOLA_CATEGORY: category
reStructuredText:
.. category: category
Org:
#+AUTHOR: Author #+OPTIONS: author:t email:nil
reStructuredText:
.. author: Author
Org:
#+AUTHOR: Author #+EMAIL: emailaddress@example.com #+OPTIONS: author:t email:t
reStructuredText:
.. author: Author (emailaddress@example.com)
Org:
#+NIKOLA_LINK: http://some
reStructuredText:
.. link: http://some
Org:
#+NIKOLA_PASSWORD: password
reStructuredText:
.. password: password
Org:
#+NIKOLA_NOCOMMENTS: True
reStructuredText:
.. nocomments: True
Org:
#+NIKOLA_ANNOTATIONS: True
or
#+NIKOLA_NOANNOTATIONS: True
reStructuredText:
.. annotations: True
or
.. noannotations: True
Org:
#+NIKOLA_TYPE: text
reStructuredText:
.. type: text
Org:
#+NIKOLA_HIDETITLE: True
reStructuredText:
.. hidetitle: True
Org:
#+NIKOLA_PREVIEWIMAGE: images/looks_great_on_facebook.png
reStructuredText:
.. previewimage: images/looks_great_on_facebook.png
Org:
#+NIKOLA_ENCLOSURE: images/looks_great_on_feed.png
reStructuredText:
.. Enclosure: images/looks_great_on_feed.png
Org:
#+RST: .. TEASER_END #+RST: .. TEASER_END: click to read the rest of the article
reStructuredText:
.. TEASER_END
.. TEASER_END: click to read the rest of the article
I use Auto Insert Mode and yasnippet for Nikola Org skeleton:
(auto-insert-mode)
(setq auto-insert-query nil)
(setq auto-insert-directory "~/templates/")
(setq auto-insert 'other)
(defun my/autoinsert-yas-expand ()
"Replace text in yasnippet template."
(yas-expand-snippet (buffer-string) (point-min) (point-max)))
(setq auto-insert-alist
(append
'((("blog/.*\\.org$" . "org-mode") . ["nikola.org" my/autoinsert-yas-expand])
(("\\.org$" . "org-mode") . ["template.org" my/autoinsert-yas-expand])
) auto-insert-alist))
and the ~/templates/nikola.org is as follows.
#+TITLE: `(replace-regexp-in-string "-" " " (file-name-base))` #+AUTHOR: Author #+EMAIL: mailaddress@example.com #+DATE: `(format-time-string "%Y/%m/%d %H:%M" (current-time))` #+DESCRIPTION: #+KEYWORDS: #+OPTIONS: H:4 num:nil toc:nil ::t |:t ^:t -:t f:t *:t <:t #+OPTIONS: tex:t todo:t pri:nil tags:t texht:nil #+OPTIONS: author:nil creator:nil email:nil date:t #+MACRO: teaser #+RST: .. TEASER_END
To create a new post, you will find-file ~/docs/blog/how-to-make-money.org
.
(require 'ox-publish)
(require 'ox-nikola)
(defun auto-export-my-blog ()
(let* ((project-plist (cdr (assoc "blog" org-publish-project-alist)))
(project-dir (expand-file-name
(plist-get project-plist :base-directory))))
(save-excursion
(if (string= project-dir (file-name-directory buffer-file-name))
(org-publish-current-file)))))
(add-hook 'after-save-hook 'auto-export-my-blog)
(add-to-list 'org-publish-project-alist
'("blog" . (:base-directory "~/docs/blog/"
:base-extension "org"
:publishing-directory "~/nikola/mysite/posts/"
:publishing-function (org-nikola-publish-to-rst))))
:body-only t)))
Every time you save ~/docs/blog/how-to-make-money.org
, ~/nikola/mysite/posts/how-to-make-money.rst
will be published.