diff --git a/.emacs.d/site-lisp/eltuki.el b/.emacs.d/site-lisp/eltuki.el index 4815108..80400a9 100644 --- a/.emacs.d/site-lisp/eltuki.el +++ b/.emacs.d/site-lisp/eltuki.el @@ -163,9 +163,13 @@ (eltuki-slugify-string (eltuki-get-title)))) (defun eltuki-write-content (dir) - (with-current-buffer (org-export-region-as-html - (point-min) (point-max) t "*eltuki-html*") - (write-region (point-min) (point-max) (concat dir "/content")))) + (let ((org-export-with-toc nil) + (filename (concat dir "/content"))) + (with-current-buffer (org-export-region-as-html + (point-min) (point-max) t "*eltuki-html*") + (write-region (point-min) (point-max) filename) + (kill-buffer)) + filename)) (defun eltuki-write-metadata (dir) (let ((timestamp (eltuki-get-timestamp)) @@ -173,7 +177,8 @@ (status (eltuki-get-status)) (title (eltuki-get-title)) (name (eltuki-slugify-string (eltuki-get-title))) - (commentstatus (eltuki-get-comment-status))) + (commentstatus (eltuki-get-comment-status)) + (filename (concat dir "/metadata"))) (with-temp-buffer (insert "timestamp: " timestamp "\n" "tags: " tags "\n" @@ -181,17 +186,36 @@ "title: " title "\n" "name: " name "\n" "comment_status: " commentstatus) - (write-region (point-min) (point-max) (concat dir "/metadata"))))) + (write-region (point-min) (point-max) filename)) + filename)) + +(defun eltuki-save-org (buffer dir) + (let ((filename (concat dir "/post.org"))) + (with-current-buffer buffer + (write-file filename)) + filename)) + +(defun eltuki-git-add (file) + (shell-command (concat "cd " eltuki-blog-dir "; git add '" (expand-file-name file) "'"))) + +(defun eltuki-commit () + (shell-command (concat "cd " eltuki-blog-dir "; git commit -m \"new post: \\\"" (eltuki-get-title) + "\\\"\""))) (defun eltuki-finish () (interactive) - (let ((buffer (get-buffer "*eltuki*")) + (let ((buffer (or (get-buffer "*eltuki*") + (current-buffer))) (dest (eltuki-get-directory))) (unless (file-exists-p dest) (mkdir dest)) - (eltuki-write-content dest) - (eltuki-write-metadata dest) + (mapc #'eltuki-git-add + (list (eltuki-write-content dest) + (eltuki-write-metadata dest) + (eltuki-save-org buffer dest))) + + (eltuki-commit) (kill-buffer buffer))) (provide 'eltuki)