Skip to content

Instantly share code, notes, and snippets.

Created August 9, 2023 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanisErdmanis/94da86eecfeeef7b9e38f2c0a7abf367 to your computer and use it in GitHub Desktop.
Save JanisErdmanis/94da86eecfeeef7b9e38f2c0a7abf367 to your computer and use it in GitHub Desktop.
Compiling `.org` files into a personal website with `org-publish`
(require 'ox)
(require 'cl-lib)
(require 'cl)
(setq make-backup-files nil) ;; No need for backup files
(defvar my-base-directory (concat (file-name-directory load-file-name) "org")
"Org sources are taken from folder org relative to this file")
(defvar my-publishing-directory (concat (file-name-directory load-file-name) "html")
"Everything is published in folder html relative to this file")
(load-file (concat (file-name-directory load-file-name) "html-link.el"))
(defun pd-html-template (contents info)
;; Existing file name. Could be usefull for if clauses
(rbase (file-relative-name (plist-get info :base-directory) (file-name-directory (plist-get info ':input-file))))
;; Relative file name starting from base directory
(rfname (file-relative-name (plist-get info ':input-file) (plist-get info :base-directory)))
(concat "
<!DOCTYPE html>
<html lang=\"en\">
<!-- Basic Page Needs
================================================== -->
<meta charset=\"utf-8\">
<!-- Mobile Specific Metas
================================================== -->
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\">
<!-- CSS
================================================== -->
(format "<link rel=\"stylesheet\" href=\"%s/stylesheets/base.css\">\n" rbase)
(format "<link rel=\"stylesheet\" href=\"%s/stylesheets/skeleton.css\">\n" rbase)
(format "<link rel=\"stylesheet\" href=\"%s/stylesheets/layout.css\">\n" rbase)
<style type=\"text/css\">
b {
font-weight: bold;
body {
font-size:12pt;font-family:\"PT Serif\", serif;
text-rendering: optimizeLegibility;
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
<!-- Favicons
================================================== -->
<!-- <link rel=\"shortcut icon\" href=\"images/favicon.ico\"> -->
<script type=\"text/x-mathjax-config\">
MathJax.Hub.Config({\"HTML-CSS\": { scale: 75}});
<script type=\"text/javascript\"
" <div class=\"container\">
<!-- Header -->
;; <div class=\"sixteen columns\">
(format "<h1 class=\"remove-bottom\" style=\"margin-top: 40px; color: #ad3f39; display: inline-block;\">%s</h1>&nbsp"
(org-export-data (or (plist-get info :title) "") info))
(format "%s" (org-export-data (or (plist-get info :date) "") info))
(format "<a href=\"%s/aboutme\">about me</a>&nbsp&nbsp&nbsp&nbsp\n" rbase) (format "<a href=\"%s/cv\">cv</a>&nbsp&nbsp&nbsp&nbsp\n" rbase)
(format "<a href=\"%s/research\">research</a>&nbsp&nbsp&nbsp&nbsp\n" rbase)
(format "<a href=\"%s/blog\">blog</a>&nbsp&nbsp&nbsp&nbsp\n" rbase)
"<hr />"
"<div id=\"home\">\n"
<div class=\"sixteen columns\">
<hr />
<small>This website was made with <a href=\"\">Skeleton</a> with modificactions from <a href=\"\">JuliaDiff</a></small>.
</div><!-- container -->
<!-- End Document
================================================== -->
(org-export-define-derived-backend 'pd-html 'html
:translate-alist '((template . pd-html-template)
(link . pd-html-link)
(defun pd-html-publish-to-html (plist filename pub-dir)
(org-publish-org-to 'pd-html filename ".html" plist pub-dir))
(setq org-publish-project-alist
:base-directory ,my-base-directory ;; Path to your org files.
:base-extension "org"
:publishing-directory ,my-publishing-directory ;; Path to your Jekyll project.
:recursive t
:publishing-function pd-html-publish-to-html ;;org-html-publish-to-html
;;:publishing-function org-html-publish-to-html
:headline-levels 6
:html-extension "html"
:with-toc nil ; don't create a table of contents
:section-numbers nil
:table-of-contents nil
:html-link-org-files-as-html t
:htmlized-source nil
(defun blog-publish ()
(org-publish "org-page-sources" t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment