org-config.el 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. ;;; Commentary:
  2. ;;;
  3. ;;; This file contains some variable definitions and functions that I use for publishing my site.
  4. (setq-default org-src-fontify-natively t) ;syntax highlighting in org-modesource blocks
  5. (setq my-html-preamble
  6. "<header id=\"banner\">
  7. <h1><a href=\"/home.html\">Kevin \"The Nuclear\" Bloom</a></h1>
  8. <hr />
  9. <nav><ul>
  10. <li><a href=\"/contact.html\">Contact</a></li>
  11. <li><a href=\"/blog/blog.html\">Blog</a></li>
  12. <li><a href=\"/projects.html\">Projects</a></li>
  13. <li><a href=\"/about-me.html\">About Me</a></li>
  14. </ul></nav>
  15. </header>")
  16. (setq org-html-head
  17. (with-temp-buffer
  18. (let ((css-dir (file-name-as-directory "~/org-site/www/styles/"))
  19. (css-files '("main.css")))
  20. (insert "<style type=\"text/css\">\n")
  21. (dolist (file css-files)
  22. (insert-file-contents (concat css-dir file)))
  23. (insert "</style>")
  24. (buffer-string))))
  25. (setq my-blog-extra-head
  26. (concat
  27. "<link rel='stylesheet' href='/../styles/main.css' />"))
  28. (defun insert-css ()
  29. (let* ((css-dir (expand-file-name (plist-get project-plist :publishing-directory)))
  30. (css-files (directory-files css-dir t "^.*\\.css$")))
  31. (dolist (file css-files)
  32. (with-temp-buffer
  33. (insert-file-contents file)
  34. (write-file file)))))
  35. (defun my-blog-get-preview (file)
  36. "The comments in FILE have to be on their own lines, prefereably before and after paragraphs.
  37. Written by Dennis Ogbe, modified by Kevin Bloom."
  38. (with-temp-buffer
  39. (insert-file-contents file)
  40. (goto-char (point-min))
  41. (let ((beg (+ 1 (re-search-forward "^#\\+BEGIN_PREVIEW$")))
  42. (end (progn (re-search-forward "^#\\+END_PREVIEW$")
  43. (match-beginning 0))))
  44. (buffer-substring beg end))))
  45. (defun my-blog-sitemap (project &optional sitemap-filename)
  46. "Generate the sitemap for my blog. Written by Dennis Ogbe, modified by Kevin Bloom."
  47. (let* ((project-plist (cdr project))
  48. (dir (file-name-as-directory
  49. (plist-get project-plist :base-directory)))
  50. (localdir (file-name-directory dir))
  51. (exclude-regexp (plist-get project-plist :exclude))
  52. (files (nreverse
  53. (org-publish-get-base-files project exclude-regexp)))
  54. (sitemap-filename (concat dir (or sitemap-filename "sitemap.org")))
  55. (sitemap-sans-extension
  56. (plist-get project-plist :sitemap-sans-extension))
  57. (visiting (find-buffer-visiting sitemap-filename))
  58. file sitemap-buffer)
  59. (with-current-buffer
  60. (let ((org-inhibit-startup t))
  61. (setq sitemap-buffer
  62. (or visiting (find-file sitemap-filename))))
  63. (erase-buffer)
  64. ;; loop through all of the files in the project
  65. (while (setq file (pop files))
  66. (let ((fn (file-name-nondirectory file))
  67. (link ;; changed this to fix links. see postprocessor.
  68. (file-relative-name file (file-name-as-directory
  69. (expand-file-name (concat (file-name-as-directory dir) "..")))))
  70. (oldlocal localdir))
  71. (when sitemap-sans-extension
  72. (setq link (file-name-sans-extension link)))
  73. ;; sitemap shouldn't list itself
  74. (unless (equal (file-truename sitemap-filename)
  75. (file-truename file))
  76. (let (;; get the title and date of the current file
  77. (title (org-publish-format-file-entry "%t" file project-plist))
  78. (date (org-publish-format-file-entry "%d" file project-plist))
  79. ;; get the preview section from the current file
  80. (preview (my-blog-get-preview file))
  81. (regexp "\\(.*\\)\\[\\([^][]+\\)\\]\\(.*\\)"))
  82. ;; insert a horizontal line before every post, kill the first one
  83. ;; before saving
  84. (insert "-----\n")
  85. (cond ((string-match-p regexp title)
  86. (string-match regexp title)
  87. ;; insert every post as headline
  88. (insert (concat"* " (match-string 1 title)
  89. "[[file:" link "]["
  90. (match-string 2 title)
  91. "]]" (match-string 3 title) "\n")))
  92. (t (insert (concat "* [[file:" link "][" title "]]\n"))))
  93. ;; add properties for `ox-rss.el' here
  94. (let ((rss-permalink (concat (file-name-sans-extension link) ".html"))
  95. (rss-pubdate (format-time-string
  96. (car org-time-stamp-formats)
  97. (org-publish-find-date file))))
  98. (org-set-property "RSS_PERMALINK" rss-permalink)
  99. (org-set-property "PUBDATE" rss-pubdate))
  100. ;; insert the date, preview, & read more link
  101. (insert (concat date "\n\n"))
  102. (insert preview)
  103. (let ((new-link (reduce (lambda (x y) (concat x "/" y)) (cdr (split-string link "/")))))
  104. (insert (concat "[[file:" new-link "][Read More...]]\n")))))))
  105. ;; kill the first hrule to make this look OK
  106. (goto-char (point-min))
  107. (let ((kill-whole-line t)) (kill-line))
  108. (save-buffer))
  109. (or visiting (kill-buffer sitemap-buffer))))
  110. (setq org-publish-project-alist
  111. `(("site" :components ("main" "main-static" "blogs" "styles"))
  112. ("main"
  113. :base-directory "~/personal/src/org-site/"
  114. :base-extension "org"
  115. :publishing-directory "~/personal/src/org-site/www/"
  116. :recursive t
  117. :publishing-function org-html-publish-to-html
  118. :headline-levels 4 ; Just the default for this project.
  119. :section-numbers nil
  120. :with-toc nil
  121. :with-drawers t
  122. :with-sub-superscript nil ;; important!!
  123. :html-link-home "/"
  124. :html-head nil ;; cleans up anything that would have been in there.
  125. :html-head-extra ,my-blog-extra-head
  126. :html-head-include-default-style nil
  127. :html-head-include-scripts nil
  128. :html-viewport nil
  129. :html-home/up-format ""
  130. :html-link-up ""
  131. :html-link-home ""
  132. ;; :auto-preamble t
  133. :html-postamble nil
  134. :html-preamble ,my-html-preamble
  135. )
  136. ("blogs"
  137. :base-directory "~/personal/src/org-site/blog"
  138. :base-extension "org"
  139. :publishing-directory "~/personal/src/org-site/www/blog"
  140. :recursive t
  141. :publishing-function org-html-publish-to-html
  142. :headline-levels 4 ; Just the default for this project.
  143. :section-numbers nil
  144. :with-toc nil
  145. :with-drawers t
  146. :with-sub-superscript nil ;; important!!
  147. :html-link-home "/"
  148. :html-head nil ;; cleans up anything that would have been in there.
  149. :html-head-extra ,my-blog-extra-head
  150. :html-head-include-default-style nil
  151. :html-head-include-scripts nil
  152. :html-viewport nil
  153. :html-home/up-format ""
  154. :html-link-up ""
  155. :html-link-home ""
  156. ;; :auto-preamble t
  157. :html-postamble nil
  158. :html-preamble ,my-html-preamble
  159. ;; sitemap - list of blog articles
  160. :auto-sitemap t
  161. :sitemap-filename "blog.org"
  162. :sitemap-title "Blog"
  163. :title "Blog Posts"
  164. ;; custom sitemap generator function
  165. :sitemap-function my-blog-sitemap
  166. :sitemap-sort-files anti-chronologically
  167. :sitemap-date-format "Published: %a %b %d %Y"
  168. )
  169. ("main-static"
  170. :base-directory "~/personal/src/org-site/"
  171. :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
  172. :publishing-directory "~/personal/org-site/www/"
  173. :recursive t
  174. :publishing-function org-publish-attachment
  175. )
  176. ("styles"
  177. :base-directory "~/personal/src/org-site/styles"
  178. :base-extension ".*"
  179. :publishing-directory "~/personal/src/org-site/www/styles/"
  180. :publishing-function org-publish-attachment
  181. ;; :completion-function insert-css
  182. )
  183. ))