ox-nikola
ox-nikola copied to clipboard
export Nikola blog posts in reStructuredText syntax from Org-Mode
#+TITLE: export Nikola blog posts in reStructuredText syntax from Org-Mode #+AUTHOR: IGARASHI Masanao #+EMAIL: [email protected] #+DATE: 2013/11/03 13:50 #+DESCRIPTION: #+KEYWORDS: #+LANGUAGE: en #+OPTIONS: H:4 num:nil toc:t ::t |:t ^:t -:t f:t *:t <:t #+OPTIONS: tex:t todo:t pri:nil tags:t texht:nil #+OPTIONS: author:t creator:nil email:nil date:t
-
Ox-Nikola
Ox-Nikola exports your [[http://orgmode.org][Org]] documents to [[http://getnikola.com][Nikola]] posts in reStructuredText. Ox-Nikola depends on [[https://github.com/masayuko/ox-rst][Ox-Rst]] and relies on the Org-mode 8.0 export framework.
-
Configuration
Add the following in your init.el
#+BEGIN_SRC emacs-lisp (require 'ox-nikola) #+END_SRC
-
reStructuredText export
=ox-nikola= export back-end generates nikola blog posts in reStructuredText syntax for an Org mode buffer.
** reStructuredText commands
To export your org document to, press =C-c C-e=, and then =n=.
*** =C-c C-e n r (org-nikola-export-to-rst)=
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.
*** =C-c C-e n R (org-nikola-export-as-rst)=
Export as a temporary buffer. Do not create a file.
** Title, Date, Slug and other Nikola header
Org: #+BEGIN_EXAMPLE ,#+TITLE: This is the title of the document ,#+AUTHOR: Author ,#+EMAIL: [email protected] ,#+DATE: 2013/12/31 00:00 ,#+DESCRIPTION: description text ,#+KEYWORDS: tag1, tag2 ,#+OPTIONS: author:nil ,#+NIKOLA_TYPE: text #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. 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 #+END_SRC
*** Updated
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_UPDATED: 2015/08/30 #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. updated: 2015/08/30 #+END_SRC
*** Slug
Org: #+BEGIN_EXAMPLE ,#+TITLE: This is the title of the document ,#+NIKOLA_SLUG: slug-for-nikola #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. title: This is the title of the document .. nikola: slug-for-nikola #+END_SRC
*** Tags
Org: #+BEGIN_EXAMPLE ,#+KEYWORDS: tag1, tag2 #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. tags: tag1, tag2 #+END_SRC
*** Section
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_SECTION: section #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. section: section #+END_SRC
*** Category
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_CATEGORY: category #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. category: category #+END_SRC
*** Author
Org: #+BEGIN_EXAMPLE ,#+AUTHOR: Author ,#+OPTIONS: author:t email:nil #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. author: Author #+END_SRC
Org: #+BEGIN_EXAMPLE ,#+AUTHOR: Author ,#+EMAIL: [email protected] ,#+OPTIONS: author:t email:t #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. author: Author ([email protected]) #+END_SRC
*** Link
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_LINK: http://some #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. link: http://some #+END_SRC
*** Password
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_PASSWORD: password #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. password: password #+END_SRC
*** Nocomments
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_NOCOMMENTS: True #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. nocomments: True #+END_SRC
*** Annotations, Noannotasions
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_ANNOTATIONS: True #+END_EXAMPLE
or
#+BEGIN_EXAMPLE ,#+NIKOLA_NOANNOTATIONS: True #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. annotations: True #+END_SRC
or
#+BEGIN_SRC rst .. noannotations: True #+END_SRC
*** Type
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_TYPE: text #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. type: text #+END_SRC
*** Hidetitle
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_HIDETITLE: True #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. hidetitle: True #+END_SRC
*** Previewimage
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_PREVIEWIMAGE: images/looks_great_on_facebook.png #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. previewimage: images/looks_great_on_facebook.png #+END_SRC
*** Enclosure
Org: #+BEGIN_EXAMPLE ,#+NIKOLA_ENCLOSURE: images/looks_great_on_feed.png #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. Enclosure: images/looks_great_on_feed.png #+END_SRC
** Teasers
Org: #+BEGIN_EXAMPLE ,#+RST: .. TEASER_END
,#+RST: .. TEASER_END: click to read the rest of the article #+END_EXAMPLE
reStructuredText: #+BEGIN_SRC rst .. TEASER_END
.. TEASER_END: click to read the rest of the article #+END_SRC
** Nikola posts template
I use [[http://www.emacswiki.org/emacs/AutoInsertMode][Auto Insert Mode]] and [[https://github.com/capitaomorte/yasnippet][yasnippet]] for Nikola Org skeleton:
#+BEGIN_SRC lisp (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)) #+END_SRC
and the ~/templates/nikola.org is as follows.
#+BEGIN_EXAMPLE
,#+TITLE: (replace-regexp-in-string "-" " " (file-name-base))
,#+AUTHOR: Author
,#+EMAIL: [email protected]
,#+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
#+END_EXAMPLE
To create a new post, you will find-file =~/docs/blog/how-to-make-money.org=.
** org-publish configuration
#+BEGIN_SRC lisp (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))) #+END_SRC
Every time you save =~/docs/blog/how-to-make-money.org=, =~/nikola/mysite/posts/how-to-make-money.rst= will be published.