From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= Subject: [RFC] Add new export backend for Jekyll Date: Sat, 17 Mar 2018 22:45:28 +0100 Message-ID: <20180317214528.16908-1-stlman@poczta.fm> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exJeG-0005MQ-CD for emacs-orgmode@gnu.org; Sat, 17 Mar 2018 17:45:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exJeD-0004DK-6f for emacs-orgmode@gnu.org; Sat, 17 Mar 2018 17:45:56 -0400 Received: from smtpo.poczta.interia.pl ([217.74.65.233]:49873) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1exJeC-00045q-MM for emacs-orgmode@gnu.org; Sat, 17 Mar 2018 17:45:53 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Cc: =?UTF-8?q?=C5=81ukasz=20Stelmach?= Jekyll[1] is a static site genrator. Its most notable deployment are Github Pages. It accepts several input formats including HTML, that is why ox-jekyll is derived from ox-html. Input files for Jekyll must be HTML files without any site-specific elements (e.g. menus, headers, sidebars), because Jekyll will add them. The HTML code, however, must be prepended with a piece of YAML code which specifies: + page title, + page category, + layout template to use for the page, + publication date. The main task of ox-jekyll is to read Org '#+KEYWORDS' and output them as Jekyll's front matter. At this point also source code blocks are exporte= d inside special tags instead of html
.

[1] http://jekyllrb.com/

Signed-off-by: =C5=81ukasz Stelmach 
---

This is kind of work-in-progress version. "Kind of" because it satisfies
my needs and I would like to ask what others think or need.

How to test this module?

Please comment.

 lisp/ox-jekyll.el | 139 ++++++++++++++++++++++++++++++++++++++++++++++++=
++++++
 1 file changed, 139 insertions(+)
 create mode 100644 lisp/ox-jekyll.el

diff --git a/lisp/ox-jekyll.el b/lisp/ox-jekyll.el
new file mode 100644
index 000000000..273792ba9
--- /dev/null
+++ b/lisp/ox-jekyll.el
@@ -0,0 +1,139 @@
+;;; ox-jekyll.el --- Export org files to Jekyll static site generator
+
+;; Copyright (C) 2011-2015 Free Software Foundation, Inc.
+
+;; Author: =C5=81ukasz Stelmach 
+;; Keywords:=20
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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.
+
+;; GNU Emacs 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 GNU Emacs.  If not, see .
+
+;;; Commentary:
+
+;; This library implements a backend to export Org files as HTML
+;; for further processing by Jekyll static site generator.
+;; See Org manual for more information.
+
+;;; Code:
+
+;;; Dependencies
+
+(require 'ox)
+
+;;; Define Back-End
+
+(org-export-define-derived-backend 'jekyll 'html
+  :menu-entry
+  '(?h 1
+       ((?J "As HTML buffer (Jekyll)" org-jekyll-export-as-html)
+        (?j "As HTML file (Jekyll)" org-jekyll-export-to-html)))
+
+  :translate-alist
+  '((template . org-jekyll-html-template)
+    (src-block . org-jekyll-html-src-block))
+
+  :options-alist
+  '((:jekyll-layout "LAYOUT" nil "post" t)
+    (:jekyll-categories "CATEGORIES" nil nil t))
+  ;; TODO: tags, as soon as I learn how they differ from categories
+  ;; https://github.com/jekyll/jekyll/issues/6853
+  )
+
+(defun org-jekyll-export-as-html
+    "TODO: Doc"
+  (&optional async subtreep visible-only body-only ext-plist)
+  (interactive)
+  (org-export-to-buffer 'jekyll "*Org JEKYLL Export*"
+    async subtreep visible-only body-only ext-plist (lambda () (html-mod=
e))))
+
+(defun org-jekyll-export-to-html
+    "TODO: Doc"
+  (&optional async subtreep visible-only body-only ext-plist)
+  (interactive)
+  (let ((file (org-export-output-file-name ".html" subtreep)))
+    (org-export-to-file 'beamer file
+      async subtreep visible-only body-only ext-plist)))
+
+(defun org-jekyll-html-src-block (src-block contents info)
+  "Transcode a SRC-BLOCK element from Org to a highlight block for Jekyl=
l.
+CONTENTS holds the contents of the item.  INFO is a plist holding
+contextual information."
+  (message "org-jekyll-html-src-block")
+  (if (org-export-read-attribute :attr_html src-block :textarea)
+      (org-html--textarea-block src-block)
+    (let ((lang (org-element-property :language src-block))
+          (caption (org-export-get-caption src-block))
+          (code (org-html-format-code src-block info))
+          (label (let ((lbl (org-element-property :name src-block)))
+                   (if (not lbl) ""
+                     (format " id=3D\"%s\""
+                             (org-export-solidify-link-text lbl))))))
+      (if (not lang) (format "
\n%s
" lab= el code) + (format + "
\n%s%s\n
" + (if (not caption) "" + (format "" + (org-export-data caption info))) + (format "\n{%% highlight %s %%}\n%s{%% endhighlight %%}" lang c= ode)))))) + +(defun org-jekyll-html-template (contents info) + "Return complete document for Jekyll, i.e. the HTML contents +without the and tags but prepended with a front +matter for Jekyll." + (let ((title (org-export-data (plist-get info :title) info)) + (date (org-export-data (plist-get info :date) info)) + (categories (org-export-data (plist-get info :jekyll-categories) info)= ) + (now (format-time-string "%FT%T%z" (current-time))) + last_mod) + (setq last_mod (if (and (stringp date) (/=3D 0 (length date))) + now + nil)) + (setq date (if (and (stringp date) (/=3D 0 (length date))) + date + (with-current-buffer (plist-get info :input-buffer) + (save-excursion + (goto-char (point-min)) + (insert "#+DATE: " now "\n"))) + now)) + (concat + (format + "--- +title: %s +date: %s +layout: %s +%s%s---\n" + title date (plist-get info :jekyll-layout) + (if (< 0 (length categories)) + (concat "categories:\n - " + (mapconcat 'identity + (split-string categories "," t "\\s-+") + "\n - ") =20 + "\n") + "") + (when last_mod (concat "last_modified_at: " last_mod "\n"))) + contents))) + +(defun org-html-publish-to-jekyll-html (plist filename pub-dir) + "Publish an org file to HTML for postprocessing in Jekyll. + +FILENAME is the filename of the Org file to be published. PLIST +is the property list for the given project. PUB-DIR is the +publishing directory. + +Return output file name." + (org-publish-org-to 'jekyll filename + (concat "." (or (plist-get plist :html-extension) + org-html-extension "html")) + plist pub-dir)) --=20 2.11.0