| 1 |
(use-modules (ice-9 optargs) (sxml simple) (sxml transform)) |
| 2 |
|
| 3 |
(define* (templatize body title category relative-root-path #:key (scm-path "index.scm")) |
| 4 |
(define (href . args) |
| 5 |
`(href ,(apply string-append relative-root-path args))) |
| 6 |
(define (rev? text) |
| 7 |
(if (string=? category text) |
| 8 |
'((class "reversed")) |
| 9 |
'())) |
| 10 |
(define (list-join l infix) |
| 11 |
"Infixes @var{infix} into list @var{l}." |
| 12 |
(if (null? l) l |
| 13 |
(let lp ((in (cdr l)) (out (list (car l)))) |
| 14 |
(cond ((null? in) (reverse out)) |
| 15 |
(else (lp (cdr in) (cons* (car in) infix out))))))) |
| 16 |
(define (make-navbar) |
| 17 |
`(div (@ (id "menu-bar")) |
| 18 |
,@(list-join |
| 19 |
(map (lambda (x) |
| 20 |
`(a (@ ,(href (cdr x) "/") ,@(rev? (car x))) ,(car x))) |
| 21 |
'(("documentation" . "docs") |
| 22 |
("download" . "download") |
| 23 |
("developers" . "dev") |
| 24 |
("news" . "news") |
| 25 |
|
| 26 |
|
| 27 |
)) |
| 28 |
" ") |
| 29 |
" " |
| 30 |
(a (@ (href "http://git.savannah.nongnu.org/cgit/guile-cairo.git/")) "code"))) |
| 31 |
`(html |
| 32 |
(head (title ,title) |
| 33 |
(meta (@ (name "Generator") |
| 34 |
(content "The Guile SXML Toolkit"))) |
| 35 |
(link (@ (rel "stylesheet") (type "text/css") |
| 36 |
,(href "base.css")))) |
| 37 |
(body |
| 38 |
(div (@ (id "body")) |
| 39 |
(div (@ (id "heading")) |
| 40 |
(h1 (a (@ ,(href "")) "guile-cairo")) |
| 41 |
,(make-navbar)) |
| 42 |
(div (@ (id "text")) |
| 43 |
,@body) |
| 44 |
(div (@ (id "footer")) |
| 45 |
"(powered by " (a (@ (href ,scm-path)) "sxml") ")"))))) |
| 46 |
|
| 47 |
(define *xhtml-doctype* |
| 48 |
(string-append |
| 49 |
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " |
| 50 |
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n")) |
| 51 |
|
| 52 |
(define (preprocess page transform-rules relative-root-path) |
| 53 |
(define (rlink tag path . body) |
| 54 |
`(a (@ (href ,(string-append relative-root-path path))) ,body)) |
| 55 |
(pre-post-order |
| 56 |
page |
| 57 |
`(,@transform-rules |
| 58 |
(rlink . ,rlink) |
| 59 |
(*text* . ,(lambda (tag text) text)) |
| 60 |
(*default* . ,(lambda args args))))) |
| 61 |
|
| 62 |
(define* (output-html page title category relative-root-path |
| 63 |
#:key (scm-path "index.scm") (transform-rules '())) |
| 64 |
(display *xhtml-doctype*) |
| 65 |
(sxml->xml |
| 66 |
(templatize (preprocess page transform-rules relative-root-path) |
| 67 |
title category relative-root-path #:scm-path scm-path))) |