render-locally 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/emacs --script
  2. (require 'package)
  3. (setq package-user-dir (expand-file-name "./.packages"))
  4. (setq package-archives '(("melpa" . "https://melpa.org/packages/")
  5. ("elpa" . "https://elpa.gnu.org/packages/")))
  6. ;; Initialize the package system
  7. (package-initialize)
  8. (unless package-archive-contents
  9. (package-refresh-contents))
  10. ;; Install dependencies
  11. (package-install 'htmlize)
  12. (require 'htmlize)
  13. (require 'ox-publish)
  14. (defun craggy-hurd-generate-a-href (filename local-dir label)
  15. (concat "<a href=\"" local-dir filename "\">" label "</a>"))
  16. (defun craggy-hurd-generate-navbar (local-dir)
  17. "This will generate a navbar for you, but you need to specify a
  18. list of filename links, and a local-dir, which can be './' or ../"
  19. (concat "<nav>"
  20. (craggy-hurd-generate-a-href "index.html" local-dir "Home")
  21. (craggy-hurd-generate-a-href "about.html" local-dir "About")
  22. (craggy-hurd-generate-a-href "blog/index.html" local-dir "Blog")
  23. "</nav>"))
  24. (setq craggy-hurd-stylesheets
  25. '("normalize.css" "default-org-stylesheet.css" "stylesheet.css"))
  26. (defun craggy-hurd-generate-stylesheets (filenames local-dir)
  27. "This generates an HTML link to a css file, based on the filename
  28. and local-dir, which can be either './' or '../'"
  29. (interactive)
  30. (if (null filenames)
  31. ""
  32. (concat "<link rel=\"stylesheet\" href=\""
  33. local-dir (car filenames)
  34. "\" type=\"text/css\"/>"
  35. (craggy-hurd-generate-stylesheets (cdr filenames) local-dir))))
  36. (setq org-publish-project-alist
  37. `(("craggy-hurd"
  38. :base-directory "."
  39. :publishing-directory "./rendered/"
  40. :auto-sitemap t
  41. :section-numbers nil
  42. :with-toc nil
  43. :htmlized-source t
  44. :html-head-include-default-style nil
  45. :html-head ,(craggy-hurd-generate-stylesheets
  46. craggy-hurd-stylesheets "./css/")
  47. :html-preamble ,(craggy-hurd-generate-navbar "./"))
  48. ("craggy-hurd-css"
  49. :base-directory "./css/"
  50. :publishing-function org-publish-attachment
  51. :publishing-directory "./rendered/css/"
  52. :base-extension "css")
  53. ("craggy-hurd-blog"
  54. :base-directory "./blog/"
  55. :publishing-directory "./rendered/blog/"
  56. :exclude "index.org"
  57. :html-head ,(craggy-hurd-generate-stylesheets
  58. craggy-hurd-stylesheets "../css/")
  59. :html-head-include-default-style nil
  60. :htmlized-source t
  61. :section-numbers nil
  62. :with-toc nil
  63. :html-preamble ,(craggy-hurd-generate-navbar "../")
  64. :auto-sitemap t
  65. :sitemap-filename "index.org"
  66. :sitemap-title "Blog"
  67. :sitemap-sort-files anti-chronologically)
  68. ))
  69. (org-publish-all t)
  70. (print "Build complete")