auto-prepend html/ in links in toplevel readme, remove tag from id of headers
this code is so ugly!! augh!! definitely need to rework it and find a better way to reach in and manipulate sxml trees
This commit is contained in:
parent
031f975b2c
commit
afe41bcc01
1 changed files with 27 additions and 9 deletions
36
main.scm
36
main.scm
|
@ -94,15 +94,29 @@
|
|||
(substring* 0 40)))
|
||||
|
||||
(define (enumerate-tag tag inner)
|
||||
`(,tag (@ (id ,tag "-" ,(slugify tag inner))) ,inner))
|
||||
`(,tag (@ (id ,(slugify tag inner))) ,inner))
|
||||
|
||||
(define sxml-html-rules
|
||||
(define (sxml-html-rules adjust-relative)
|
||||
`(;; assign all headings an id so you can link to them
|
||||
(h1 . ,enumerate-tag)
|
||||
(h2 . ,enumerate-tag)
|
||||
(h3 . ,enumerate-tag)
|
||||
(h4 . ,enumerate-tag)
|
||||
(h5 . ,enumerate-tag)
|
||||
;; if adjust-relative is true, all relative links should get prefixed with
|
||||
;; the relative-root.
|
||||
,(if adjust-relative
|
||||
`(a .
|
||||
,(lambda (t i)
|
||||
`(,t .
|
||||
,(alist-update
|
||||
'@
|
||||
(alist-update
|
||||
'href
|
||||
`(,adjust-relative ,(alist-ref 'href (alist-ref '@ i)))
|
||||
(alist-ref '@ i))
|
||||
i))))
|
||||
`(a . ,(lambda (t i) `(,t . ,i))))
|
||||
;; this copied from lowdown html-serialization-rules* because it
|
||||
;; is for some reason not exported??
|
||||
(*COMMENT* . ,(lambda (_ str) (list #\< "!--" str "--" #\>)))
|
||||
|
@ -219,16 +233,19 @@
|
|||
(create-directory destination-directory #t)
|
||||
'())
|
||||
|
||||
(let* (;; render the sxml to a html string that we can hand to the template
|
||||
(let* (;; vars = global vars + file-specific vars
|
||||
(vars (alist-merge vars (or newvars '())))
|
||||
(rel-root-prefix (alist-ref 'relative_root vars))
|
||||
;; render the sxml to a html string that we can hand to the template
|
||||
(body-html
|
||||
(with-output-to-string
|
||||
(lambda ()
|
||||
(SXML->HTML (pre-post-order* body-sxml sxml-html-rules)))))
|
||||
;; vars = global vars + file-specific vars + body k/v pair
|
||||
(vars
|
||||
(alist-cons
|
||||
'content body-html
|
||||
(alist-merge vars (or newvars '())))))
|
||||
(SXML->HTML (pre-post-order* body-sxml (sxml-html-rules
|
||||
(if (equal? rel-root-prefix "html/")
|
||||
rel-root-prefix
|
||||
#f)))))))
|
||||
;; vars = vars + body k/v pair
|
||||
(vars (alist-cons 'content body-html vars)))
|
||||
|
||||
(with-output-to-file output-filename
|
||||
(lambda ()
|
||||
|
@ -237,6 +254,7 @@
|
|||
;; main program ------------------------------------------------------------------------------
|
||||
|
||||
(define (generate-html-files html-repo-path templates-directory)
|
||||
;; git automatically updates this hash when you checkout/pull/etc.
|
||||
(let* ((version-ident "$Id$")
|
||||
(source-files-list (git-repository->paths-list))
|
||||
(template-alist
|
||||
|
|
Loading…
Reference in a new issue