(package-initialize) (require 'ox-publish) (defvar this-date-format "%Y-%m-%d") (defun me/html-preamble (plist) "PLIST: An entry." (if (org-export-get-date plist this-date-format) (plist-put plist :subtitle (format "Published on %s" (org-export-get-date plist this-date-format) ))) ;; Preamble (with-temp-buffer (insert-file-contents "../html-templates/preamble.html") (buffer-string))) (defun me/html-postamble (plist) (with-temp-buffer (insert-file-contents "../html-templates/postamble.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 "%s - *[[file:posts/%s][%s]]*" (format-time-string this-date-format (org-publish-find-date entry project)) entry (org-publish-find-title 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 me/org-publish-do-nothing (plist filename pub-dir) "") (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][%s]]* - %s\n<<%s>>\n\n%s" (file-name-sans-extension entry) (format-time-string this-date-format (org-publish-find-date entry project)) (org-publish-find-title entry project) (file-name-sans-extension entry) (org-publish-find-content entry project) )) ((eq style 'tree) (file-name-nondirectory (directory-file-name entry))) (t entry))) (defun me/org-publish-microblog (plist filename pub-dir) "Publish RSS with PLIST, only when FILENAME is '../pages/microblog.org'. PUB-DIR is when the output will be placed." (if (equal "../pages/microblog.org" (file-name-nondirectory filename)) (org-html-publish-to-html plist filename pub-dir))) (defun my-blog-local-mathjax () ; '((path "/js/MathJax.js?config=TeX-AMS-MML_HTMLorMML") '((path "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML") (scale "100") (align "center") (indent "2em") (tagside "right") (mathml nil))) (setq org-publish-project-alist '(("posts" :base-directory "posts/" :base-extension "org" :publishing-directory "site/posts" :recursive nil :publishing-function org-html-publish-to-html :auto-sitemap t :section-numbers nil :sitemap-format-entry me/org-posts-sitemap-format-entry :sitemap-title "Yuchen's Blog" :sitemap-sort-files anti-chronologically :sitemap-filename "../pages/blog.org" :html-head " " :html-preamble me/html-preamble :html-self-link-headlines t :author ("Yuchen Pei") :html-postamble me/html-postamble :html-mathjax-options ((path "/js/mathjax/MathJax.js?config=TeX-AMS_CHTML")) :html-mathjax-template "" ) ("microposts" :base-directory "microposts/" :base-extension "org" :publishing-directory "site/microposts" :recursive t :publishing-function me/org-publish-microblog :auto-sitemap t :sitemap-format-entry me/org-microposts-sitemap-format-entry :sitemap-function me/org-microposts-sitemap :sitemap-title "Yuchen's Microblog" :sitemap-sort-files anti-chronologically :sitemap-filename "../pages/microblog.org" :html-head "" :html-preamble me/html-preamble :author ("Yuchen Pei") :html-postamble me/html-postamble :html-mathjax-options ((path "/js/mathjax/MathJax.js?config=TeX-AMS_CHTML")) :html-mathjax-template "" ) ("pages" :base-directory "pages/" :base-extension "org" :publishing-directory "site/" :recursive t :publishing-function org-html-publish-to-html :html-head " " :html-preamble me/html-preamble :author ("Yuchen Pei") :html-postamble me/html-postamble :html-prefer-user-labels t :html-mathjax-options ((path "/js/mathjax/MathJax.js?config=TeX-AMS_CHTML")) :html-mathjax-template "" ) ("css" :base-directory "css/" :base-extension "css" :publishing-directory "site/css" :publishing-function org-publish-attachment :recursive t ) ("js" :base-directory "js/" :base-extension "js" :publishing-directory "site/js" :publishing-function org-publish-attachment :recursive t ) ("all" :components ("posts" "microposts" "pages" "css" "js"))))