Skip to content

Instantly share code, notes, and snippets.

@sathlan
Created January 9, 2013 07:34
Show Gist options
  • Save sathlan/4491366 to your computer and use it in GitHub Desktop.
Save sathlan/4491366 to your computer and use it in GitHub Desktop.
skeleton for a basic blog exporter.
; use org-make-options-regexp to catch BLOG_DIR in #+BLOG_DIR that can
; be overload in a property :BLOG_DIR:. Same mechanism for
; BLOG_AUTHOR, BLOG_MAIL, BLOG_CATEGORY, BLOG_TAG. For this tag,
; BLOG_TAG, we can have multiple values.
(defun ch:org-export-blog ()
(let* ((tree (org-copy-subtree))
(buf (generate-new-buffer "*testing export*"))
(blog_dir "/tmp")
(blog_author "")
(blog_mail "")
(blog_category "")
(blog_tag "")
(text (buffer-substring-no-properties (region-beginning) (region-end)))
(opt-plist (org-combine-plists
(org-default-export-plist)
(org-infile-export-plist))))
(set-buffer buf)
(org-mode)
(org-paste-subtree 1)
(goto-char (point-min))
(org-mark-subtree)
(org-activate-mark)
(let ((rb (region-beginning))
(re (region-end))
(fname (concat (file-name-as-directory blog_dir)
(downcase
(concat
(replace-regexp-in-string "[ \t]" "_"
(save-excursion
(goto-char (point-min))
(org-get-heading t t)))
".org")))))
(message fname)
(write-region rb re fname nil nil nil nil)
(deactivate-mark)
(goto-char (point-min))
(kill-buffer buf)
(find-file-other-window fname))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment