;;; Copyright © 2019 Amin Bandali ;;; ;;; This program is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as ;;; published by the Free Software Foundation; either version 3 of the ;;; License, or (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see ;;; . (define-module (bandali theme) #:use-module (bandali prefs) ; my-* #:use-module (bandali tags) ; tag-* #:use-module (bandali utils) #:use-module (haunt builder blog) ; theme #:use-module (haunt post) ; post-* #:use-module (haunt site) ; site-* #:use-module (haunt utils) ; string->date* #:use-module (srfi srfi-19) #:export (base-layout post-uri post-list-table bandali-theme)) (define* (base-layout site body #:key title copy license-page?) `((doctype "html") (html (head (meta (@ (charset "utf-8"))) (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) (title ,(if title (string-append title " — " (site-title site)) "Amin Bandali’s Personal Site")) (link (@ (rel "icon") (href "/gnu.ico"))) ,(stylesheet "reset") ,(stylesheet "style")) (body (main ,body) (footer (p "Copyright © " ,(if copy copy "2016–2019") " Amin Bandali. See " ,(if license-page? "the above" (aa "license.html" "/license.html")) " for license conditions. Please copy and share.")))))) (define* (post-uri site post #:optional prefix) (string-append (or prefix "") "/" (site-post-slug site post) ".html")) (define* (post-list-table site posts #:optional prefix) `((table (@ (class "post-list")) (tbody ,@(map (lambda (post) `(tr (td ,(aa (post-ref post 'title) (post-uri site post prefix))) (td (small ,(date->string (post-date post) my-date-format))))) posts))))) (define (my-post-template post) `((header (h1 ,(post-ref post 'title)) (address "By " ,(aa (post-ref post 'author) "/") " <" ,(post-ref post 'email) ">") (p (@ (class "date")) "Published " ,(date->string (post-date post) my-date-format)) ,(if (post-ref post 'updated) `(p (@ (class "updated")) "Updated " ,(date->string (post-ref post 'updated) my-date-format)) '()) ,(if (post-ref post 'tags) `(p (@ (class "tags")) "Tagged " ,@(intersperse (map (lambda (tag) (aa tag (tag-uri my-tag-prefix tag))) (post-ref post 'tags)) ", ")) '())) ,(post-sxml post) (p (@ (class "muted inbox")) "Have a question or comment? Start a discussion in my " ,(aa "public inbox" "https://lists.sr.ht/~bandali/public-inbox") " by sending an email to " ,(aa "~bandali/public-inbox@lists.sr.ht" "mailto:~bandali/public-inbox@lists.sr.ht") (small " [" ,(aa "mailing list etiquette" "https://man.sr.ht/lists.sr.ht/etiquette.md") "]") "."))) (define* (my-collection-template site title posts prefix #:optional all-posts tag) `((h2 ,title ,(if tag (aa `(img (@ (class "feed-icon-h2") (src "/icon-16px.png") (alt "subscribe to atom feed"))) (tag-uri my-tag-prefix tag ".xml")) '())) ,(post-list-table site posts prefix) (h2 (@ (id "tags")) "Tags") ,(tag-links (or all-posts posts)) ,(if tag '(a (@ (href "/notes.html")) "← all notes") '()))) (define bandali-theme (theme #:name "bandali" #:layout (lambda (site title body) (base-layout site body #:title title)) #:post-template my-post-template #:collection-template my-collection-template)) (module-define! (resolve-module '(haunt builder blog)) 'render-post (lambda (theme site post) (let ((title (post-ref post 'title)) (body ((theme-post-template theme) post)) (copy (post-ref post 'copyright))) (base-layout site body #:title title #:copy copy)))) (register-metadata-parser! 'updated string->date*)