Skip to content

export Nikola blog posts in reStructuredText syntax from Org-Mode

Notifications You must be signed in to change notification settings

msnoigrs/ox-nikola

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 

Repository files navigation

export Nikola blog posts in reStructuredText syntax from Org-Mode

Ox-Nikola

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.

Configuration

Add the following in your init.el

(require 'ox-nikola)

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:

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

Updated

Org:

#+NIKOLA_UPDATED: 2015/08/30

reStructuredText:

.. updated: 2015/08/30

Slug

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

Tags

Org:

#+KEYWORDS: tag1, tag2

reStructuredText:

.. tags: tag1, tag2

Section

Org:

#+NIKOLA_SECTION: section

reStructuredText:

.. section: section

Category

Org:

#+NIKOLA_CATEGORY: category

reStructuredText:

.. category: category

Author

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)

Link

Org:

#+NIKOLA_LINK: http://some

reStructuredText:

.. link: http://some

Password

Org:

#+NIKOLA_PASSWORD: password

reStructuredText:

.. password: password

Nocomments

Org:

#+NIKOLA_NOCOMMENTS: True

reStructuredText:

.. nocomments: True

Annotations, Noannotasions

Org:

#+NIKOLA_ANNOTATIONS: True

or

#+NIKOLA_NOANNOTATIONS: True

reStructuredText:

.. annotations: True

or

.. noannotations: True

Type

Org:

#+NIKOLA_TYPE: text

reStructuredText:

.. type: text

Hidetitle

Org:

#+NIKOLA_HIDETITLE: True

reStructuredText:

.. hidetitle: True

Previewimage

Org:

#+NIKOLA_PREVIEWIMAGE: images/looks_great_on_facebook.png

reStructuredText:

.. previewimage: images/looks_great_on_facebook.png

Enclosure

Org:

#+NIKOLA_ENCLOSURE: images/looks_great_on_feed.png

reStructuredText:

.. Enclosure: images/looks_great_on_feed.png

Teasers

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

Nikola posts template

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.

org-publish configuration

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

About

export Nikola blog posts in reStructuredText syntax from Org-Mode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published