Skip to content

Instantly share code, notes, and snippets.

@dmb2
Created January 16, 2013 14:38
Show Gist options
  • Save dmb2/4547520 to your computer and use it in GitHub Desktop.
Save dmb2/4547520 to your computer and use it in GitHub Desktop.
;;; 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)))))

Project Notes

Tasks

Task a

Notes about task a

Task b

Task c

Notes

<2013-01-14 Mon> Dated Entry 1

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla posuere. Donec vitae dolor. Nullam tristique diam non turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam vestibulum accumsan nisl.

Subheading for entry 1

<2013-01-15 Tue> Another Dated entry

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla posuere. Donec vitae dolor. Nullam tristique diam non turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam vestibulum accumsan nisl.

<2013-01-16 Wed> A Classified entry

Privileged eyes only, do not export! My super secret plans:

Blah

Blah Blah

Unorganized Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment