diff options
author | David Thompson <dthompson2@worcester.edu> | 2024-09-24 10:35:07 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2024-09-24 10:35:07 -0400 |
commit | b4f7435aab4270ddb7adcb58a7baf75d70132782 (patch) | |
tree | 0f3045dfc2b0c77a7563f78c403821f13ae98527 | |
parent | 1f07b6076ae3e35177f481efdc9107b6d4d0611a (diff) |
flat-pages: Add index metadata flag for pretty URLs.
-rw-r--r-- | doc/haunt.texi | 20 | ||||
-rw-r--r-- | example/haunt.scm | 2 | ||||
-rw-r--r-- | example/pages/about.md | 10 | ||||
-rw-r--r-- | haunt/builder/flat-pages.scm | 9 |
4 files changed, 38 insertions, 3 deletions
diff --git a/doc/haunt.texi b/doc/haunt.texi index acc7257..0ac016f 100644 --- a/doc/haunt.texi +++ b/doc/haunt.texi @@ -908,6 +908,26 @@ of demonstrating Haunt's flat page functionality. I live here in this manual with my two cats: Bob and Carol. @end example +If the above text were saved to @file{about.md} in the flat pages +directory, the resulting HTML page would be @file{about.html}. + +For ``pretty'' URLS (@file{/about} rather than @file{/about.html}), +the special metadata item @code{index: true} can be specified in the +page header: + +@example +title: About me +index: true +--- + +# About me + +... +@end example + +With the @code{index} metadata flag, Haunt will generate +@file{about/index.html} rather than @file{about.html}. + The content of each flat page is inserted into a complete HTML document by the @var{template} procedure. This procedure takes three arguments: diff --git a/example/haunt.scm b/example/haunt.scm index 2527c89..bcb58fd 100644 --- a/example/haunt.scm +++ b/example/haunt.scm @@ -2,6 +2,7 @@ (haunt builder blog) (haunt builder atom) (haunt builder assets) + (haunt builder flat-pages) (haunt builder rss) (haunt publisher rsync) (haunt publisher sourcehut) @@ -21,6 +22,7 @@ (atom-feed) (atom-feeds-by-tag) (rss-feed) + (flat-pages) (static-directory "images")) #:publishers (list (rsync-publisher #:name 'rsync #:destination "/tmp/haunt-example") diff --git a/example/pages/about.md b/example/pages/about.md new file mode 100644 index 0000000..d841fa7 --- /dev/null +++ b/example/pages/about.md @@ -0,0 +1,10 @@ +title: About +index: true +--- +Scheme is a cool programming language. + +Guile is a cool Scheme implementation. + +Haunt is a cool static site generator written in Guile. + +Enough said. diff --git a/haunt/builder/flat-pages.scm b/haunt/builder/flat-pages.scm index edf778a..d0594ca 100644 --- a/haunt/builder/flat-pages.scm +++ b/haunt/builder/flat-pages.scm @@ -80,12 +80,15 @@ complete HTML page that presumably wraps the page body." (#f (error "no reader available for page" file-name)) (reader (let-values (((metadata body) (reader-read reader file-name))) - (let* ((dir (substring (dirname file-name) + (let* ((title (or (assq-ref metadata 'title) "Untitled")) + (index? (equal? (assq-ref metadata 'index) "true")) + (dir (substring (dirname file-name) (string-length directory))) (out (string-append prefix dir (if (string-null? dir) "" "/") - (strip-extension file-name) ".html")) - (title (or (assq-ref metadata 'title) "Untitled"))) + (strip-extension file-name) + (if index? "/index" "") + ".html"))) (serialized-artifact out (template site title body) sxml->html)))))) src-files))) |