builder: blog: Set default values for 'theme' keywords.

Previously if a user did not provide a value for any of the theme
keyword arguments, there would be an error.  Instead, provide defaults
from ugly-theme.

* haunt/builder/blog.scm: (ugly-default-layout, ugly-default-post-template,
ugly-default-collection-template): New variables.
(theme): New defaults to keyword arguments.
This commit is contained in:
Christopher Allan Webber 2016-02-16 10:44:22 -08:00 committed by David Thompson
parent a37c3cd585
commit 961f061c4b
1 changed files with 37 additions and 33 deletions

View File

@ -1,5 +1,6 @@
;;; Haunt --- Static site generator for GNU Guile ;;; Haunt --- Static site generator for GNU Guile
;;; Copyright © 2015 David Thompson <davet@gnu.org> ;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
;;; ;;;
;;; This file is part of Haunt. ;;; This file is part of Haunt.
;;; ;;;
@ -53,11 +54,41 @@
(post-template theme-post-template) (post-template theme-post-template)
(collection-template theme-collection-template)) (collection-template theme-collection-template))
(define (ugly-default-layout site title body)
`((doctype "html")
(head
(meta (@ (charset "utf-8")))
(title ,(string-append title " — " (site-title site))))
(body
(h1 ,(site-title site))
,body)))
(define (ugly-default-post-template post)
`((h2 ,(post-ref post 'title))
(h3 "by " ,(post-ref post 'author)
" — " ,(date->string* (post-date post)))
(div ,(post-sxml post))))
(define (ugly-default-collection-template site title posts prefix)
(define (post-uri post)
(string-append "/" (or prefix "")
(site-post-slug site post) ".html"))
`((h3 ,title)
(ul
,@(map (lambda (post)
`(li
(a (@ (href ,(post-uri post)))
,(post-ref post 'title)
" — "
,(date->string* (post-date post)))))
posts))))
(define* (theme #:key (define* (theme #:key
(name "Untitled") (name "Untitled")
layout (layout ugly-default-layout)
post-template (post-template ugly-default-post-template)
collection-template) (collection-template ugly-default-collection-template))
(make-theme name layout post-template collection-template)) (make-theme name layout post-template collection-template))
(define (with-layout theme site title body) (define (with-layout theme site title body)
@ -78,36 +109,9 @@
(define ugly-theme (define ugly-theme
(theme #:name "Ugly" (theme #:name "Ugly"
#:layout #:layout ugly-default-layout
(lambda (site title body) #:post-template ugly-default-post-template
`((doctype "html") #:collection-template ugly-default-collection-template))
(head
(meta (@ (charset "utf-8")))
(title ,(string-append title " — " (site-title site))))
(body
(h1 ,(site-title site))
,body)))
#:post-template
(lambda (post)
`((h2 ,(post-ref post 'title))
(h3 "by " ,(post-ref post 'author)
" — " ,(date->string* (post-date post)))
(div ,(post-sxml post))))
#:collection-template
(lambda (site title posts prefix)
(define (post-uri post)
(string-append "/" (or prefix "")
(site-post-slug site post) ".html"))
`((h3 ,title)
(ul
,@(map (lambda (post)
`(li
(a (@ (href ,(post-uri post)))
,(post-ref post 'title)
" — "
,(date->string* (post-date post)))))
posts))))))
(define* (blog #:key (theme ugly-theme) prefix (define* (blog #:key (theme ugly-theme) prefix
(collections (collections