From 1dcfacfa22cc50a95ab057023ed58dcb0608c05e Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 26 Mar 2024 19:06:18 +0200 Subject: Improve stuff --- feed.scm | 79 +++++++- main.scm | 22 ++- static/Merriweather-Black.ttf | Bin 0 -> 141700 bytes static/Merriweather-BlackItalic.ttf | Bin 0 -> 142620 bytes static/Merriweather-Bold.ttf | Bin 0 -> 142040 bytes static/Merriweather-BoldItalic.ttf | Bin 0 -> 143832 bytes static/Merriweather-Italic.ttf | Bin 0 -> 142648 bytes static/Merriweather-Light.ttf | Bin 0 -> 148124 bytes static/Merriweather-LightItalic.ttf | Bin 0 -> 142056 bytes static/Merriweather-Regular.ttf | Bin 0 -> 149120 bytes static/OFL.txt | 93 +++++++++ static/style.css | 164 ++++++++++++++++ template.html | 8 +- utils.scm | 10 + vendor/bin/pandoc-rss | 227 ++++++++++++++++++++++ vendor/share/pandoc-rss/data/language-codes | 103 ++++++++++ vendor/share/pandoc-rss/data/templates/date.value | 1 + vendor/share/pandoc-rss/data/templates/item.xml | 14 ++ 18 files changed, 713 insertions(+), 8 deletions(-) create mode 100644 static/Merriweather-Black.ttf create mode 100644 static/Merriweather-BlackItalic.ttf create mode 100644 static/Merriweather-Bold.ttf create mode 100644 static/Merriweather-BoldItalic.ttf create mode 100644 static/Merriweather-Italic.ttf create mode 100644 static/Merriweather-Light.ttf create mode 100644 static/Merriweather-LightItalic.ttf create mode 100644 static/Merriweather-Regular.ttf create mode 100644 static/OFL.txt create mode 100644 static/style.css create mode 100755 vendor/bin/pandoc-rss create mode 100644 vendor/share/pandoc-rss/data/language-codes create mode 100644 vendor/share/pandoc-rss/data/templates/date.value create mode 100644 vendor/share/pandoc-rss/data/templates/item.xml diff --git a/feed.scm b/feed.scm index de1d4ac..57a0afb 100644 --- a/feed.scm +++ b/feed.scm @@ -1,4 +1,4 @@ -(module feed (generate-feed) +(module feed (generate-feed generate-archive-index) (import scheme (chicken base) (chicken format) @@ -6,12 +6,16 @@ (chicken io) (chicken process) (chicken pathname) + (chicken irregex) + srfi-1 + srfi-13 + srfi-132 utils) - (define (generate-feed archive-dir out-dir) + (define (generate-feed src-dir archive-dir out-dir) (define paths (glob (format "~A/*" archive-dir))) (define output-port - (process "pandoc-rss" + (process "vendor/bin/pandoc-rss" (apply list "-s" "-t" "jan's garden" "-d" "RSS feed for Jan's personal digital garden" @@ -22,5 +26,70 @@ "-w" "https://jan.systems" paths))) (define output (read-string #f output-port)) - (with-output-to-file (make-pathname out-dir "feed.xml") - (λ () (print output))))) + (define out-path (make-pathname out-dir "feed.xml")) + (printf "[info] writing RSS feed to \"~A\"~%" out-path) + (with-output-to-file out-path + (λ () (print output)))) + + (define (collect-fm-lines lines #!optional (acc '())) + (if (string=? "---" (car lines)) + acc + (collect-fm-lines (cdr lines) (cons (car lines) acc)))) + + (define (extract-field field fm) (call/cc (@ extract-field* field fm))) + (define (extract-field* field fm return) + (define (search line) + (define irx (format "^~A: (.+?)$" field)) + (define m (irregex-search irx line)) + (if m + (return (submatch m)))) + + (for-each search fm) + #f) + + (define (read-md-frontmatter md-path) + (define lines (with-input-from-file md-path + (λ () (read-lines)))) + + (define (inner return) + (if (not (string=? "---" (car lines))) + (return #f)) + + (define fm (collect-fm-lines (cdr lines))) + `((title . ,(extract-field "title" fm)) + (date . ,(extract-field "date" fm)) + (kind . ,(extract-field "kind" fm)))) + + (call/cc (@ inner))) + + (define (generate-archive-index archive-dir src-dir) + (define paths (pipe (glob (format "~A/*" archive-dir)) + (@ filter (@ irregex-search "\\.md$")))) + + (define index-alist (map (λ (path) (cons path (read-md-frontmatter path))) paths)) + ;; newest first + (define (compare a b) + (string>? (assocdr 'date (cdr a)) (assocdr 'date (cdr b)))) + + (list-sort! compare index-alist) + + (define (to-li pair) + (define path (car pair)) + (define title (assocdr 'title (cdr pair))) + (define date (assocdr 'date (cdr pair))) + (define kind (assocdr 'kind (cdr pair))) + (define link (pipe path + (@ replace (format "^~A\\/?" src-dir) "/") + (@ replace "\\.md$" ".html"))) + (format "* [~A (~A) [~A]](~A)" title date kind link)) + + (define index-lis (map to-li index-alist)) + (define out-md (string-append "---\n" + "title: Archive\n" + "---\n" + "# Archive\n\n" + (string-join index-lis "\n"))) + + (with-output-to-file (make-pathname archive-dir "index.md") + (λ () (print out-md)))) + ) diff --git a/main.scm b/main.scm index 150c3d4..4459b75 100644 --- a/main.scm +++ b/main.scm @@ -27,6 +27,8 @@ "template.html")) (define feed-dir (or (get-environment-variable "FEED_DIR") (make-pathname src-dir "archive"))) +(define static-dir (or (get-environment-variable "STATIC_DIR") + "static")) (assert (> (string-length src-dir) 0)) (assert (> (string-length out-dir) 0)) @@ -118,12 +120,28 @@ (delete-file path))) (for-each (@ delete) (glob (format "~A/*" dir)))) +(define (remove-old-archive-index) + (define path (make-pathname feed-dir "index.md")) + (if (file-exists? path) + (delete-file path))) + +(define (copy-directory from to) + (read-string #f (process "cp" (list "-r" + from + to)))) + ;; run -(printf "[info] generating feed from directory \"~A\"~%" feed-dir) -(generate-feed feed-dir out-dir) +(printf "[info] removing old archive index.md~%") +(remove-old-archive-index) (printf "[info] cleaning up output directory \"~A\"~%" out-dir) (clean-dir out-dir) +(printf "[info] generating feed from archive directory \"~A\"~%" feed-dir) +(generate-feed src-dir feed-dir out-dir) +(printf "[info] generating archive index.md~%") +(generate-archive-index feed-dir src-dir) (printf "[info] generating site with pages from \"~A\"~%" src-dir) (process-dir src-dir) +(printf "[info] copying static files from \"~A\"~%" static-dir) +(copy-directory static-dir (make-pathname out-dir static-dir)) (printf "[info] done.~%") diff --git a/static/Merriweather-Black.ttf b/static/Merriweather-Black.ttf new file mode 100644 index 0000000..50c3b33 Binary files /dev/null and b/static/Merriweather-Black.ttf differ diff --git a/static/Merriweather-BlackItalic.ttf b/static/Merriweather-BlackItalic.ttf new file mode 100644 index 0000000..4879aba Binary files /dev/null and b/static/Merriweather-BlackItalic.ttf differ diff --git a/static/Merriweather-Bold.ttf b/static/Merriweather-Bold.ttf new file mode 100644 index 0000000..3e10e02 Binary files /dev/null and b/static/Merriweather-Bold.ttf differ diff --git a/static/Merriweather-BoldItalic.ttf b/static/Merriweather-BoldItalic.ttf new file mode 100644 index 0000000..5b9d0ec Binary files /dev/null and b/static/Merriweather-BoldItalic.ttf differ diff --git a/static/Merriweather-Italic.ttf b/static/Merriweather-Italic.ttf new file mode 100644 index 0000000..8e9d03d Binary files /dev/null and b/static/Merriweather-Italic.ttf differ diff --git a/static/Merriweather-Light.ttf b/static/Merriweather-Light.ttf new file mode 100644 index 0000000..034ef03 Binary files /dev/null and b/static/Merriweather-Light.ttf differ diff --git a/static/Merriweather-LightItalic.ttf b/static/Merriweather-LightItalic.ttf new file mode 100644 index 0000000..4d19550 Binary files /dev/null and b/static/Merriweather-LightItalic.ttf differ diff --git a/static/Merriweather-Regular.ttf b/static/Merriweather-Regular.ttf new file mode 100644 index 0000000..3fecc77 Binary files /dev/null and b/static/Merriweather-Regular.ttf differ diff --git a/static/OFL.txt b/static/OFL.txt new file mode 100644 index 0000000..03dd415 --- /dev/null +++ b/static/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2016 The Merriweather Project Authors (https://github.com/EbenSorkin/Merriweather), with Reserved Font Name "Merriweather". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..d6ee94d --- /dev/null +++ b/static/style.css @@ -0,0 +1,164 @@ +body { + font-size: 16px; + margin: 20px auto; + padding: 10px 15px; + max-width: 800px; + + font-family: "Merriweather", serif; + font-optical-sizing: auto; + font-weight: 400; + font-style: normal; + + line-height: 35px; + + hyphens: initial; +} + +:root { + --dark--text-color: #fff; + --dark--link-color: #bbf; + --dark--bg-color: #222; + --dark--blockquote-color: #ccc; + --dark--blockquote-bg-color: #60606020; + --dark--code-bg-color: #353535; + + --light--text-color: #1a1a1a; + --light--link-color: #0090a0; + --light--bg-color: #fff; + --light--blockquote-color: #606060; + --light--blockquote-bg-color: #c8c8c820; + --light--code-bg-color: #eee; +} + +@media (prefers-color-scheme: dark) { + :root { + --text-color: var(--dark--text-color); + --link-color: var(--dark--link-color); + --bg-color: var(--dark--bg-color); + --blockquote-color: var(--dark--blockquote-color); + --blockquote-bg-color: var(--dark--blockquote-bg-color); + --code-bg-color: var(--dark--code-bg-color); + } +} +@media (prefers-color-scheme: light) { + :root { + --text-color: var(--light--text-color); + --link-color: var(--light--link-color); + --bg-color: var(--light--bg-color); + --blockquote-color: var(--light--blockquote-color); + --blockquote-bg-color: var(--light--blockquote-bg-color); + --code-bg-color: var(--light--code-bg-color); + } +} + +html.dark { + --text-color: var(--dark--text-color); + --link-color: var(--dark--link-color); + --bg-color: var(--dark--bg-color); + --blockquote-color: var(--dark--blockquote-color); + --blockquote-bg-color: var(--dark--blockquote-bg-color); + --code-bg-color: var(--dark--code-bg-color); +} + +html.light { + --text-color: var(--light--text-color); + --link-color: var(--light--link-color); + --bg-color: var(--light--bg-color); + --blockquote-color: var(--light--blockquote-color); + --blockquote-bg-color: var(--light--blockquote-bg-color); + --code-bg-color: var(--light--code-bg-color); +} + +html { + color: var(--text-color); + background-color: var(--bg-color); +} + +a, a:visited { + color: var(--link-color); +} + +blockquote { + color: var(--blockquote-color); +} + +#dark-mode-btn { + border: none; + background: none; + font-size: 30px; + cursor: pointer; +} + +.header-row { + display: flex; + flex-flow: row nowrap; + align-items: center; + justify-content: space-between; + + margin: 30px 0; +} + +.header-row h1 { + margin: 0; +} + +.page-title { + text-decoration: none; + color: var(--text-color) !important; + font-size: 32px; + font-weight: 700; +} + +.page-title:hover { + text-decoration: underline; +} + +code { + padding: 8px 10px; + background-color: var(--code-bg-color); +} + +pre, div.sourceCode { + padding: 8px 10px; + overflow-x: scroll; + background-color: var(--code-bg-color); +} + +img { + max-width: 100%; + width: 100%; + margin: 20px 0; +} + +blockquote { + display: block; + background-color: var(--blockquote-bg-color); + border-left: 10px solid var(--link-color); + margin: 20px 0; + padding: 2px 10px; + quotes: "\201C""\201D""\2018""\2019"; +} + +figure { + max-width: 100%; + padding: 0; + margin: 10px 0; + display: block; +} + +hr { + background: none !important; + height: 0; + margin: 40px auto; + border: none; + border-top: 2px dotted var(--text-color) !important; + width: 50%; +} + +.nojs-hidden { + display: none; +} + +small { + color: grey; +} diff --git a/template.html b/template.html index d0160cd..b6c4aaf 100644 --- a/template.html +++ b/template.html @@ -63,7 +63,7 @@ $endif$
-

jan's garden

+ jan's garden
+ $if(title)$ + $if(hide-body-title)$ + $else$ +

$title$ $if(date)$($date$)$endif$ $if(kind)$[$kind$]$endif$

+ $endif$ + $endif$ $body$