diff options
Diffstat (limited to 'publish.el')
-rw-r--r-- | publish.el | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/publish.el b/publish.el new file mode 100644 index 0000000..a9c3a5c --- /dev/null +++ b/publish.el @@ -0,0 +1,119 @@ +(require 'ox-publish) + +(defvar this-date-format "%Y-%m-%d") + +(defun me/html-preamble-post (plist) + "PLIST: An entry." + (if (org-export-get-date plist this-date-format) + (plist-put plist + :subtitle (format "Published on %s by %s" + (org-export-get-date plist this-date-format) + (car (plist-get plist :author))))) + ;; Preamble + (with-temp-buffer + (insert-file-contents "../html-templates/post-preamble.html") (buffer-string))) + +(defun me/org-posts-sitemap-format-entry (entry style project) + "Format posts with author and published data in the index page. + +ENTRY: file-name +STYLE: +PROJECT: `posts in this case." + (cond ((not (directory-name-p entry)) + (format "*[[file:posts/%s][%s]]* - %s" + entry + (org-publish-find-title entry project) + (format-time-string this-date-format + (org-publish-find-date entry project)))) + ((eq style 'tree) (file-name-nondirectory (directory-file-name entry))) + (t entry))) + +(defun me/org-microposts-sitemap (title list) + "Default site map, as a string. +TITLE is the title of the site map. LIST is an internal +representation for the files to include, as returned by +`org-list-to-lisp'. PROJECT is the current project." + (concat "#+TITLE: " title "\n\n" + (org-list-to-org list))) + + +(defun org-publish-find-content (file project) + (let ((file (org-publish--expand-file-name file project))) + (when (and (file-readable-p file) (not (directory-name-p file))) + (with-temp-buffer + (insert-file-contents file) + (goto-char (point-min)) + (let ((beg (+ 1 (re-search-forward "^$")))) +; (print (concat file ": " (number-to-string beg) ", " (number-to-string (point-max)))) + (buffer-substring beg (point-max))))))) + +(defun me/org-microposts-sitemap-format-entry (entry style project) + "Format posts with author and published data in the index page. + +ENTRY: file-name +STYLE: +PROJECT: `posts in this case." + (cond ((not (directory-name-p entry)) + (format "%s - *[[file:microposts/%s][%s]]*\n\n%s" + (format-time-string this-date-format + (org-publish-find-date entry project)) + entry + (org-publish-find-title entry project) + (org-publish-find-content entry project) + )) + ((eq style 'tree) (file-name-nondirectory (directory-file-name entry))) + (t entry))) + +(setq org-publish-project-alist + '(("posts" + :base-directory "posts/" + :base-extension "org" + :publishing-directory "site/posts" + :recursive t + :publishing-function org-html-publish-to-html + :auto-sitemap t + :sitemap-format-entry me/org-posts-sitemap-format-entry + :sitemap-title "All posts" + :sitemap-sort-files anti-chronologically + :sitemap-filename "../pages/blog.org" + :html-head "<link rel='stylesheet' href='../css/default.css' type='text/css'/>" + :html-preamble me/html-preamble-post + :author ("Yuchen Pei") + :html-postamble "" + ) + ("microposts" + :base-directory "microposts/" + :base-extension "org" + :publishing-directory "site/microposts" + :recursive t + :publishing-function org-html-publish-to-html + :auto-sitemap t + :sitemap-format-entry me/org-microposts-sitemap-format-entry + :sitemap-function me/org-microposts-sitemap + :sitemap-title "Microblog" + :sitemap-sort-files anti-chronologically + :sitemap-filename "../pages/microblog.org" + :html-head "<link rel='stylesheet' href='../css/default.css' type='text/css'/>" + :html-preamble me/html-preamble-post + :author ("Yuchen Pei") + :html-postamble "" + ) + ("pages" + :base-directory "pages/" + :base-extension "org" + :publishing-directory "site/" + :recursive t + :publishing-function org-html-publish-to-html + :html-head "<link rel='stylesheet' href='../css/default.css' type='text/css'/>" + :html-preamble me/html-preamble-post + :author ("Yuchen Pei") + :html-postamble "" + ) + ("css" + :base-directory "css/" + :base-extension "css" + :publishing-directory "site/css" + :publishing-function org-publish-attachment + :recursive t + ) + ("all" :components ("posts" "microposts" "pages" "css")))) |