Created
November 4, 2012 09:10
-
-
Save suhailshergill/4011020 to your computer and use it in GitHub Desktop.
blog.el
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(setq org-export-htmlize-output-type 'css) | |
(setq org-footnote-section nil) | |
(setq org-footnote-auto-label t) | |
(setq org-time-stamp-custom-formats | |
'("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M %z>")) | |
(defun su/journal/select-current-entry () | |
"helper to select current org entry" | |
(org-back-to-heading) | |
(set-mark (point)) | |
(org-end-of-subtree) | |
) | |
(defun su/utils/filter-timestamps (timestamp) | |
"remove surrounding square/angle brackets if any" | |
(let* ( | |
(timestamp | |
(replace-regexp-in-string "<\\([^>]+\\)>" "\\1" timestamp)) | |
(timestamp | |
(replace-regexp-in-string "\\[\\([^]]+\\)\\]" "\\1" timestamp)) | |
) | |
timestamp | |
)) | |
(defun su/blog/format-timestrings (timestring) | |
"normalize timestrings into `yyyy-mm-dd hh:mm:ss tz' format" | |
(let ((time (date-to-time timestring))) | |
(format-time-string "%Y-%m-%d %T %Z" time))) | |
(defun su/blog/normalize-timestamps (timestamp) | |
"normalize all timestamps" | |
(su/blog/format-timestrings (su/utils/filter-timestamps timestamp))) | |
(defun su/journal-export-db (&optional debug) | |
"wrapper to publish journal entries to my blog" | |
(interactive "P") | |
(save-excursion | |
(su/journal/select-current-entry) | |
(let* ( | |
(debug (or debug su/debugging-mode)) | |
(custom-id (org-entry-get nil "CUSTOM_ID")) | |
(tags (org-get-tags-at)) | |
(heading (org-get-heading t)) | |
(entered-on (su/blog/normalize-timestamps | |
(org-entry-get nil "TIMESTAMP_IA"))) | |
(updated-on (su/blog/normalize-timestamps | |
(or (org-entry-get nil "UPDATED_ON") entered-on))) | |
(properties (org-entry-properties)) | |
(entry | |
(let ( | |
(org-export-allow-BIND t) | |
(org-confirm-babel-evaluate nil) | |
(org-footnote-section "Footnotes") | |
(org-export-html-footnotes-section | |
(concat | |
"<div class=\"footnotes\" id=\"footnotes-" custom-id "\">\n" | |
"<h2 class=\"footnotes\">%s: </h2>\n" | |
"<div id=\"text-footnotes-" custom-id "\">\n%s\n</div>\n" | |
"</div>")) | |
) | |
(org-export-as-html 3 nil nil 'string t nil)) | |
) | |
(has-math (if su/org-export-have-math | |
"True" | |
"False")) | |
(haskell-dir (concat (getenv "HOME") "/config/hacking/haskell/")) | |
(mode (if debug "Development" | |
"Production")) | |
(stderr (if debug | |
(concat haskell-dir "publish-stderr.txt") | |
t)) | |
) | |
(with-temp-buffer | |
(insert-for-yank-1 entry) | |
(call-remote-process-region (point-min) | |
(point-max) | |
t (cons t (cons stderr nil)) t | |
:host "chaos" | |
:init "cd ~/virtualEnvs/blog/src/blog; ../../.virthualenv/cabal/bin/publish-entry" | |
:args (mode custom-id entered-on updated-on | |
heading has-math) | |
:rest-args tags) | |
) | |
) | |
) | |
) | |
(defun su/journal-delete-db (&optional debug) | |
"wrapper to delete journal entries from blog" | |
(interactive "P") | |
(flet ((org-get-tags-at (&optional pos local) | |
'())) | |
(su/journal-export-db debug))) | |
(defun su/org-export-htmlize-region-for-paste (beg end) | |
"wrapper to interactively call org-export-htmlize-region-for-paste" | |
(interactive "r") | |
(let* ((html (org-export-htmlize-region-for-paste beg end))) | |
(string-match "<pre>" html) | |
(kill-new (replace-match "<pre class=\"emacs\">" nil t html)))) | |
(global-set-key (kbd "C-c h") 'su/org-export-htmlize-region-for-paste) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment