|
;;; lab-notebook.el -- Helper functions to publish a lab notebook with |
|
;;; org-mode and jekyll |
|
|
|
;; Copyright (C) 2013 David Bjergaard |
|
|
|
;; Author: David Bjergaard <[email protected]> |
|
;; Keywords: log, lab notebook, org-mode, jekyll, github |
|
|
|
;; 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 2, 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; see the file COPYING. If not, write to the |
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
;; Boston, MA 02111-1307, USA. |
|
|
|
;;; Commentary: |
|
|
|
;; This is a set of org-mode related functions to integrate org-mode, |
|
;; jekyll, github into a lab-notebook style blog system for |
|
;; documenting scientific computing projects. |
|
|
|
(defvar *git-project-path* "~/dbjergaard.github.com" |
|
"Path to the git repository containing the source code for this project") |
|
(defun org-publish-file-to-jekyll () |
|
"Iterate over current buffer and export those entries with a |
|
date and the 'export' tag. Files are exported to |
|
'`*git-project-path*'/_posts/<date>-title.html'. Where the date |
|
and title are extracted from the headline of the entry" |
|
(interactive) |
|
(save-excursion |
|
(let ((notebook-file (expand-file-name (buffer-file-name) |
|
(file-name-directory (buffer-file-name)))) |
|
(post-dir (expand-file-name "_posts" *git-project-path*)) |
|
(yaml-front-matter '(("layout" . "default")))) |
|
(mapc |
|
(lambda (top-level) |
|
(find-file notebook-file) |
|
(goto-char (point-min)) |
|
(outline-next-visible-heading 1) |
|
(org-map-tree |
|
(lambda () |
|
(let ((tags (org-entry-get nil "TAGS")) |
|
(time (org-entry-get nil "TIMESTAMP"))) |
|
(message "time: %s" time) |
|
(when (and (string-match ":export:" (if tags tags "blah")) time) |
|
(let* ((heading (org-get-heading)) |
|
(title (replace-regexp-in-string |
|
"[:=\(\)\?]" "" |
|
(replace-regexp-in-string |
|
"[ \t]" "-" heading))) |
|
(str-time (and (string-match "\\([[:digit:]\-]+\\) " time) |
|
(match-string 1 time))) |
|
(to-file (format "%s-%s.html" str-time title)) |
|
(org-buffer (current-buffer)) |
|
(yaml-front-matter (cons (cons "title" heading) yaml-front-matter)) |
|
html) |
|
(org-narrow-to-subtree) |
|
(setq html (org-export-as-html nil nil nil 'string t nil)) |
|
(set-buffer org-buffer) (widen) |
|
(with-temp-file (expand-file-name to-file post-dir) |
|
(when yaml-front-matter |
|
(insert "---\n") |
|
(mapc (lambda (pair) |
|
(insert (format "%s: %s\n" (car pair) (cdr pair)))) |
|
yaml-front-matter) |
|
(insert html)) |
|
(get-buffer org-buffer)))))))) |
|
'(1 2))))) |