]> git.vanrenterghem.biz Git - www2.vanrenterghem.biz.git/commitdiff
Voeg eerste werkbare Mustache versie toe.
authorFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Sat, 9 Dec 2023 06:37:34 +0000 (14:37 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Sat, 9 Dec 2023 06:37:34 +0000 (14:37 +0800)
html/footer.html [deleted file]
html/footer.mustache [new file with mode: 0644]
html/navbar.html [deleted file]
html/navbar.mustache [new file with mode: 0644]
maak-website.el

diff --git a/html/footer.html b/html/footer.html
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/html/footer.mustache b/html/footer.mustache
new file mode 100644 (file)
index 0000000..3642471
--- /dev/null
@@ -0,0 +1 @@
+<script src="/assets/styles/bootstrap-5.3.0/js/bootstrap.bundle.min.js"></script>
diff --git a/html/navbar.html b/html/navbar.html
deleted file mode 100644 (file)
index 787a91f..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<nav class="navbar navbar-expand-md d-flex justify-content-start" style="background-color: #bbddff;">
-  <div class="container-fluid d-flex justify-content-start flex-row">
-    <a class="navbar-brand" aria-current="page" href="/index.html">
-      <img src="/assets/logo-100.png" width="99" height="78"/></a>
-    <ul class="navbar-nav d-flex justify-content-start mb-2 mb-lg-0 fw-bold">
-      <li class="nav-item">
-       <a class="nav-link" href="http://photos.vanrenterghem.biz/">Photos</a></li>
-      <li class="nav-item">
-       <a class="nav-link" href="/sitemap.html">Blog</a></li>
-      <li class="nav-item">
-       <a class="nav-link" href="http://git.vanrenterghem.biz/">Projects</a></li>
-    </ul>
-  </div>
-  <div class="justify-content-end mb-2 mb-lg-0 d-none d-md-block">
-    <a class="navbar-brand fs-2 fw-bold" href="/index.html">vanrenterghem.biz</a>
-  </div>
-</nav>
diff --git a/html/navbar.mustache b/html/navbar.mustache
new file mode 100644 (file)
index 0000000..787a91f
--- /dev/null
@@ -0,0 +1,17 @@
+<nav class="navbar navbar-expand-md d-flex justify-content-start" style="background-color: #bbddff;">
+  <div class="container-fluid d-flex justify-content-start flex-row">
+    <a class="navbar-brand" aria-current="page" href="/index.html">
+      <img src="/assets/logo-100.png" width="99" height="78"/></a>
+    <ul class="navbar-nav d-flex justify-content-start mb-2 mb-lg-0 fw-bold">
+      <li class="nav-item">
+       <a class="nav-link" href="http://photos.vanrenterghem.biz/">Photos</a></li>
+      <li class="nav-item">
+       <a class="nav-link" href="/sitemap.html">Blog</a></li>
+      <li class="nav-item">
+       <a class="nav-link" href="http://git.vanrenterghem.biz/">Projects</a></li>
+    </ul>
+  </div>
+  <div class="justify-content-end mb-2 mb-lg-0 d-none d-md-block">
+    <a class="navbar-brand fs-2 fw-bold" href="/index.html">vanrenterghem.biz</a>
+  </div>
+</nav>
index 1bb4897df7156725ce6da9d3cd00b151f34b85b8..f20dc4bd908e053f3b52cb70b6c975c58c24bd69 100644 (file)
@@ -1,41 +1,9 @@
 (require 'ox-publish)
 
 (setq org-html-doctype "html5")
 (require 'ox-publish)
 
 (setq org-html-doctype "html5")
-(setq org-html-divs '((preamble "header" "top")
-                        (content "main" "content")
-                        (postamble "footer" "postamble"))
-      org-html-container-element "section")
 (setq org-html-head-include-default-style nil)
 ;(setq org-html-htmlize-output-type 'css) ; default: 'inline-css
 
 (setq org-html-head-include-default-style nil)
 ;(setq org-html-htmlize-output-type 'css) ; default: 'inline-css
 
-(defun website-header (info)
-  (with-temp-buffer
-    (insert-file-contents "~/websites/stage.vanrenterghem.biz/html/navbar.html")
-    (buffer-string)))
-
-(defun post-header (exp-plist)
-  (with-temp-buffer
-    (insert (format "<nav aria-label=\"breadcrumb\">
-              <ol class=\"breadcrumb\">
-               <li class=\"breadcrumb-item\"><a href=\"/\">Home</a></li>
-               <li class=\"breadcrumb-item\"><a href=\"/sitemap.html\">Blog</a></li>
-               <li class=\"breadcrumb-item active\" aria-current=\"page\">%s</li>
-              </ol>
-            </nav>"
-           (or (org-export-data (plist-get exp-plist ':title) exp-plist)
-               "none")))
-    (goto-char (point-min))
-    (insert-file-contents "~/websites/stage.vanrenterghem.biz/html/post-header.html")
-    ;(goto-char (point-max))
-    ;(insert (format "<p>Tags: %s</p>"
-       ;           (or (org-export-data (plist-get exp-plist :filetags) exp-plist)
-       ;       "none")))
-    (buffer-string)))
-
-(defun website-footer (info)
-  (with-temp-buffer
-    (insert-file-contents "~/websites/stage.vanrenterghem.biz/html/footer.html")
-    (buffer-string)))
 
 (defun my-org-publish-sitemap-default-entry (entry style project)
   "My format for site map ENTRY, as a string.
 
 (defun my-org-publish-sitemap-default-entry (entry style project)
   "My format for site map ENTRY, as a string.
@@ -51,47 +19,136 @@ PROJECT is the current project."
         (file-name-nondirectory (directory-file-name entry)))
        (t entry)))
 
         (file-name-nondirectory (directory-file-name entry)))
        (t entry)))
 
+(defun my-blog-parse-sitemap-list (l)
+  "Convert the sitemap list in to a list of filenames."
+  (mapcar #'(lambda (i)
+              (let ((link (with-temp-buffer
+                            (let ((org-inhibit-startup nil))
+                              (insert (car i))
+                              (org-mode)
+                              (goto-char (point-min))
+                              (org-element-link-parser)))))
+                (when link
+                  (plist-get (cadr link) :path))))
+          (cdr l)))
+
+(defun my-blog-sort-article-list (l p)
+  "sort the article list anti-chronologically."
+  (sort l #'(lambda (a b)
+              (let ((d-a (org-publish-find-date a p))
+                    (d-b (org-publish-find-date b p)))
+                (not (time-less-p d-a d-b))))))
+
+(defun my-blog-get-preview (file)
+  "Clips a section of a post in FILE to be used as preview in the sitemap.
+Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the first section between 2 blank lines."
+  (with-temp-buffer
+    (insert-file-contents file)
+    (goto-char (point-min))
+    (let* ((beg (or (re-search-forward "^#\\+BEGIN_PREVIEW$" nil t 1)
+                   (re-search-forward "^$")))
+           (end (or (if (re-search-forward "^#\\+END_PREVIEW$" nil t 1)
+                       (match-beginning 0))
+                   (progn (goto-char (+ 1 beg))
+                          (re-search-forward "^$" nil t 2)))))
+      (buffer-substring beg end))))
+
+(defun my-blog-sitemap (title list)
+  "Generate the sitemap landing page for my blog."
+  (my-plain-publish-sitemap-default title list)
+  (with-temp-buffer
+    ;; mangle the parsed list given to us into a plain lisp list of files
+    (let* ((filenames (my-blog-parse-sitemap-list list))
+           (project-plist (assoc "posts" org-publish-project-alist))
+           (articles (my-blog-sort-article-list filenames project-plist)))
+      (dolist (file filenames)
+       (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file))
+               (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/"))
+               (title (org-publish-find-title file project-plist))
+               (date (format-time-string (car org-time-stamp-formats) (org-publish-find-date file project-plist)))
+               (preview (my-blog-get-preview abspath))
+              )
+          ;; insert a horizontal line before every post, kill the first one
+          ;; before saving
+          (insert "-----\n")
+          (insert (concat "* [[file:" relpath "][" title "]]\n"))
+          ;; add properties for `ox-rss.el' here
+                                       ;(let ((rss-permalink (concat (file-name-sans-extension relpath) ".html"))
+                                       ;      (rss-pubdate date))
+                                       ;  (org-set-property "RSS_PERMALINK" rss-permalink)
+                                       ;  (org-set-property "PUBDATE" rss-pubdate))
+          ;; insert the date, preview, & read more link
+          (insert (concat "Published: " date "\n\n"))
+         (insert preview)
+                                       ;(insert (concat "#+INCLUDE: \"" relpath "\" :only-contents t :lines \"1-10\"\n"))
+          (insert "\n")
+          (insert (concat "[[file:" relpath "][Read More...]]\n"))))
+      ;; kill the first hrule to make this look OK
+      (goto-char (point-min))
+      (let ((kill-whole-line t)) (kill-line))
+      ;; insert a title and save
+      (insert "#+OPTIONS: title:nil\n")
+      (insert "#+TITLE: Blog\n")
+      (insert "#+AUTHOR: Frederik Vanrenterghem\n")
+      (insert "#+EMAIL: frederik@vanrenterghem.biz\n")
+      (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
+      (insert "#+mustache-template: ~/websites/stage.vanrenterghem.biz/html/post-index.mustache\n")
+      (insert "\n")
+      (buffer-string))))
+
+(defun my-plain-publish-sitemap-default (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."
+  (with-temp-file "~/websites/stage.vanrenterghem.biz/source/sitemap.org"
+    (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
+    (insert (concat "#+TITLE: " title "\n\n"))
+    (insert (org-list-to-org list))))
+
 (setq org-publish-project-alist
 (setq org-publish-project-alist
-      '(("pages"
+      '(("landing"
          :base-directory "~/websites/stage.vanrenterghem.biz/source/"
          :base-extension "org"
          :base-directory "~/websites/stage.vanrenterghem.biz/source/"
          :base-extension "org"
+        :include ("posts/sitemap.org")
          :publishing-directory "~/websites/stage.vanrenterghem.biz/target"
          :publishing-directory "~/websites/stage.vanrenterghem.biz/target"
-         :publishing-function org-html-publish-to-html
+        :publishing-function org-mustache-html-publish-to-html
+        :mustache-template "~/websites/stage.vanrenterghem.biz/html/landing.mustache"
          :headline-levels 3
          :section-numbers nil
          :with-toc nil
         :html-head-include-default-style nil
          :headline-levels 3
          :section-numbers nil
          :with-toc nil
         :html-head-include-default-style nil
-         :html-head "<link href=\"/assets/styles/bootstrap-5.3.0/css/bootstrap.min.css\" rel=\"stylesheet\" />"
-         :html-preamble t
-        :html-preamble website-header
-        :html-postamble website-footer
+         :html-head nil
+        :html-divs nil
+         :html-preamble nil
+        :html-postamble nil
         )
 
        ("posts"
          :base-directory "~/websites/stage.vanrenterghem.biz/source/posts/"
          :base-extension "org"
         )
 
        ("posts"
          :base-directory "~/websites/stage.vanrenterghem.biz/source/posts/"
          :base-extension "org"
-         :publishing-directory "~/websites/stage.vanrenterghem.biz/target"
-         :publishing-function org-html-publish-to-html
-         :exclude "assets*\\|sitemap.org\\|index.org" ;; regexp
-        :html-content-class "container content inlinepage card h-entry"
-         :headline-levels 3
+         :publishing-directory "~/websites/stage.vanrenterghem.biz/target/posts"
+         :publishing-function org-mustache-html-publish-to-html
+        :mustache-template "~/websites/stage.vanrenterghem.biz/html/post.mustache"
+         :exclude "assets*\\|index.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp
+        :html-content-class nil
          :section-numbers nil
          :with-toc nil
         :with-title nil
          :section-numbers nil
          :with-toc nil
         :with-title nil
+        :sitemap-title "All posts"
         :html-head-include-default-style nil
         :html-head-include-default-style nil
-         :html-head "<link href=\"/assets/styles/bootstrap-5.3.0/css/bootstrap.min.css\" rel=\"stylesheet\" />\n
-        <link href=\"/assets/styles/org-htmlize.css\" rel=\"stylesheet\" />"
-         :html-preamble t
-        :html-divs ((preamble "header" "preamble")
-            (content "article" "inlinepage card h-entry")
-            (postamble "footer" "postamble"))
+         :html-head nil
+        :html-divs nil
         :recursive t
         :auto-sitemap t
         :recursive t
         :auto-sitemap t
-        :html-preamble post-header
-        :html-postamble website-footer
+        :html-preamble nil
+        :html-postamble nil
         :sitemap-sort-folders ignore-errors
         :sitemap-sort-folders ignore-errors
-        :sitemap-format-entry my-org-publish-sitemap-default-entry
+        :sitemap-function my-blog-sitemap
+         ;:sitemap-function org-publish-sitemap-default
+        ;:sitemap-format-entry my-org-publish-sitemap-default-entry
         :sitemap-sort-files anti-chronologically
         :sitemap-sort-files anti-chronologically
+        :sitemap-filename "sitemap.org"
         )
 
         ("assets"
         )
 
         ("assets"
@@ -101,4 +158,4 @@ PROJECT is the current project."
          :publishing-directory "~/websites/stage.vanrenterghem.biz/target/assets/"
          :publishing-function org-publish-attachment)
 
          :publishing-directory "~/websites/stage.vanrenterghem.biz/target/assets/"
          :publishing-function org-publish-attachment)
 
-        ("website" :components ("posts" "pages" "assets"))))
+        ("website" :components ("posts" "landing" "assets"))))