2022-12-07 19:17:44 -05:00
|
|
|
#!/usr/bin/csi -s
|
2022-12-04 15:17:29 -05:00
|
|
|
|
2022-12-13 00:34:09 -05:00
|
|
|
(import
|
|
|
|
(chicken file)
|
|
|
|
(chicken format)
|
|
|
|
(chicken io)
|
|
|
|
(chicken pathname)
|
|
|
|
(chicken port)
|
|
|
|
(chicken process)
|
|
|
|
(chicken process-context)
|
|
|
|
(chicken string)
|
|
|
|
(clojurian syntax)
|
2022-12-16 12:28:55 -05:00
|
|
|
ersatz
|
2022-12-13 00:34:09 -05:00
|
|
|
lowdown
|
2022-12-16 12:28:55 -05:00
|
|
|
scss
|
2022-12-13 00:34:09 -05:00
|
|
|
srfi-1 ;; list utils
|
|
|
|
srfi-13 ;; string utils
|
|
|
|
srfi-14 ;; charsets
|
|
|
|
sxml-transforms
|
|
|
|
symbol-utils ;; (unspecified-value)
|
|
|
|
utf8
|
|
|
|
)
|
2022-12-02 16:41:55 -05:00
|
|
|
|
2022-12-10 16:33:38 -05:00
|
|
|
;; small utilities ---------------------------------
|
|
|
|
|
2022-12-18 12:59:59 -05:00
|
|
|
|
2022-12-10 16:33:38 -05:00
|
|
|
;; (bail [message [exit-status]])
|
|
|
|
;; end the program immediately.
|
|
|
|
;; if a message is provided, print it to the screen.
|
|
|
|
;; exit-status defaults to 1.
|
2022-12-16 12:28:54 -05:00
|
|
|
(define (bail #!optional msg (status 1))
|
|
|
|
(when msg (print msg))
|
|
|
|
(exit status))
|
2022-12-10 16:33:38 -05:00
|
|
|
|
2022-12-28 00:51:48 -05:00
|
|
|
;; clojureish "debugging by print statement" tool since i still haven't reached
|
|
|
|
;; lisp enlightenment
|
|
|
|
(define ((inspect #!optional label #!rest args) s)
|
|
|
|
(display (list label ":" args " => " s) (current-error-port))
|
|
|
|
(newline (current-error-port))
|
|
|
|
s)
|
|
|
|
|
2022-12-10 16:33:38 -05:00
|
|
|
;; decompose a path s into its constituent parts. returns values:
|
|
|
|
;;
|
2022-12-16 12:28:55 -05:00
|
|
|
;; root: "/" if it's an absolute path, "" if relative directory-elements: a list
|
|
|
|
;; of each directory from root, () if none basename: the filename with extension
|
|
|
|
;; removed like "readme" or ".bashrc" extension: the file extension with the
|
|
|
|
;; dot, like ".txt" or "" if none relative-root: the relative path from the
|
|
|
|
;; given path to the root
|
2022-12-10 16:33:38 -05:00
|
|
|
;; e.g foo/bar/baz.html -> ../../
|
|
|
|
;;
|
|
|
|
;; this is intended to provide default values that make for easier reassembly
|
|
|
|
;; into filenames.
|
|
|
|
;;
|
|
|
|
;; typical use:
|
|
|
|
;; (->> source-file
|
|
|
|
;; (pathparts)
|
|
|
|
;; (define-values (root elements basename extension relative-root)))
|
|
|
|
;;
|
|
|
|
(define (pathparts s)
|
|
|
|
(define-values (dirname basename extension)
|
|
|
|
(decompose-pathname s))
|
|
|
|
(define-values (origin root directory-elements)
|
|
|
|
(decompose-directory (or dirname "")))
|
|
|
|
;; discarding origin because idgaf about windows
|
|
|
|
(values (or root "")
|
|
|
|
(or directory-elements '())
|
|
|
|
basename
|
|
|
|
(if extension (string-append "." extension) "")
|
|
|
|
(->>
|
|
|
|
(or directory-elements '())
|
|
|
|
(map (constantly "../"))
|
|
|
|
(apply string-append))))
|
|
|
|
|
2022-12-13 12:23:23 -05:00
|
|
|
;; like (substring) but doesn't break if start and end are too big/small
|
|
|
|
(define (substring* s start end)
|
|
|
|
(substring s (max start 0) (min end (string-length s))))
|
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
;; merge alists a and b. values in b "win"
|
|
|
|
(define (alist-merge a b)
|
|
|
|
(lset-union (lambda (x y) (eq? (car x) (car y))) a b))
|
|
|
|
|
2022-12-26 02:16:07 -05:00
|
|
|
;; like alist-ref but works on nested alists by specifying a path (list of keys)
|
|
|
|
(define (alist-ref-in keys alist #!optional (test eqv?))
|
|
|
|
(if (null? (cdr keys))
|
|
|
|
(alist-ref (car keys) alist test)
|
2022-12-28 00:51:48 -05:00
|
|
|
(alist-ref-in (cdr keys) (alist-ref (car keys) alist test) test)))
|
2022-12-26 02:16:07 -05:00
|
|
|
|
|
|
|
;; like alist-update, but works on nested alists by specifying a path (list of
|
|
|
|
;; keys)
|
|
|
|
(define (alist-update-in keys value alist #!optional (test eqv?))
|
2022-12-28 00:51:48 -05:00
|
|
|
(cond
|
|
|
|
((not alist) #f)
|
|
|
|
((null? (cdr keys))
|
|
|
|
(alist-update (car keys) value alist test))
|
|
|
|
(else
|
|
|
|
(alist-update (car keys)
|
|
|
|
(alist-update-in (cdr keys) value (alist-ref (car keys) alist test) test)
|
|
|
|
alist test))))
|
2022-12-26 02:16:07 -05:00
|
|
|
|
2023-01-07 15:02:19 -05:00
|
|
|
(define (unless-equals s1 s2)
|
|
|
|
;; if s1 == s2, then s1, otherwise #f
|
|
|
|
(and (equal? s1 s2) s1))
|
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
;; auto-apply ids to headings ---------------------------------
|
2023-01-07 15:02:19 -05:00
|
|
|
(define (slugify inner)
|
2022-12-16 12:28:55 -05:00
|
|
|
(->
|
|
|
|
inner
|
|
|
|
(pre-post-order*
|
|
|
|
`((*text* .
|
|
|
|
,(lambda (_ str)
|
|
|
|
(if (string? str)
|
|
|
|
(->
|
|
|
|
str
|
|
|
|
(string-downcase)
|
|
|
|
(string-translate "/,:;\"[]{}()=+")
|
|
|
|
(string-translate " _." "---"))
|
|
|
|
str)))
|
|
|
|
,@alist-conv-rules*))
|
|
|
|
(flatten)
|
|
|
|
((flip map) ->string)
|
|
|
|
(string-intersperse "")
|
|
|
|
(substring* 0 40)))
|
|
|
|
|
2023-01-07 15:02:19 -05:00
|
|
|
(define (enumerate-tag inner)
|
|
|
|
(let ((slug (slugify inner)))
|
|
|
|
`((@ (id ,slug))
|
2022-12-28 00:51:48 -05:00
|
|
|
,inner
|
|
|
|
(a (@ ((title "Permalink to this section")
|
|
|
|
(href "#" ,slug)))))))
|
2022-12-16 12:28:55 -05:00
|
|
|
|
2023-01-07 15:02:19 -05:00
|
|
|
;; a relative link to a file within our own repo should get .html added to the
|
|
|
|
;; target, since we make that filename change when rendering files for the web.
|
|
|
|
;;
|
|
|
|
;; thought it might also be good to apply that same treatment to any absolute
|
|
|
|
;; links into our repo (or other repos on the same forge?) but that gets a bit
|
|
|
|
;; messy, would need to drag variables holding current site, path, repo name all
|
|
|
|
;; the way into here
|
|
|
|
;;
|
|
|
|
;; if adjust-relative is not false, it is a prefix to be added to relative
|
|
|
|
;; links, to make the top-level readme link correctly into the site.
|
|
|
|
(define (adjust-relative-link adjust-relative inner)
|
|
|
|
(let* ((linkurl (alist-ref-in '(@ href) inner equal?))
|
|
|
|
(linkurl-startswith (cute string-prefix? <> (car linkurl))))
|
|
|
|
(if
|
|
|
|
(any linkurl-startswith '("#" "mailto:" "gemini:" "http://" "https://"))
|
|
|
|
inner
|
|
|
|
(alist-update-in '(@ href) (cons adjust-relative (append linkurl '(".html"))) inner equal?))))
|
2022-12-26 02:28:51 -05:00
|
|
|
|
2023-01-16 18:17:58 -05:00
|
|
|
;; TODO FIXME for some reason, lowdown renders links differently than images:
|
|
|
|
;; (markdown->sxml "[x](x)") => ((p (a (@ (href "x")) "x")))
|
|
|
|
;; (markdown->sxml "![x](x)") => ((p (img (@ (src ("x")) (alt "x")))))
|
|
|
|
|
2023-01-15 14:30:14 -05:00
|
|
|
(define (adjust-relative-src adjust-relative inner)
|
2023-02-01 20:22:14 -05:00
|
|
|
(let* ((srcurl
|
|
|
|
(->
|
|
|
|
;; ugh why
|
|
|
|
(alist-ref-in '(@ src) inner equal?)
|
|
|
|
(car)
|
|
|
|
((lambda (x) (if (list? x) (car x) x)))))
|
2023-01-16 18:17:58 -05:00
|
|
|
(srcurl-startswith (cute string-prefix? <> srcurl)))
|
2023-01-15 14:30:14 -05:00
|
|
|
(if
|
2023-01-16 18:17:58 -05:00
|
|
|
(or (not adjust-relative)
|
|
|
|
(not srcurl)
|
|
|
|
(any srcurl-startswith '("/" "http://" "https://")))
|
2023-01-15 14:30:14 -05:00
|
|
|
inner
|
2023-01-16 18:17:58 -05:00
|
|
|
(alist-update-in '(@ src) `((,(string-append adjust-relative srcurl))) inner equal?))))
|
2023-01-15 14:30:14 -05:00
|
|
|
|
2022-12-22 17:53:13 -05:00
|
|
|
(define (sxml-html-rules adjust-relative)
|
2022-12-16 12:28:55 -05:00
|
|
|
`(;; assign all headings an id so you can link to them
|
2023-01-07 15:02:19 -05:00
|
|
|
(h1 . ,(lambda (t i) (cons t (enumerate-tag i))))
|
|
|
|
(h2 . ,(lambda (t i) (cons t (enumerate-tag i))))
|
|
|
|
(h3 . ,(lambda (t i) (cons t (enumerate-tag i))))
|
|
|
|
(h4 . ,(lambda (t i) (cons t (enumerate-tag i))))
|
|
|
|
(h5 . ,(lambda (t i) (cons t (enumerate-tag i))))
|
2022-12-22 17:53:13 -05:00
|
|
|
;; if adjust-relative is true, all relative links should get prefixed with
|
2022-12-28 00:51:48 -05:00
|
|
|
;; the relative-root
|
2023-01-07 15:02:19 -05:00
|
|
|
(a . ,(lambda (t i) (cons t (adjust-relative-link adjust-relative i))))
|
2023-01-15 14:30:14 -05:00
|
|
|
(img . ,(lambda (t i) (cons t (adjust-relative-src adjust-relative i))))
|
2023-01-07 15:02:19 -05:00
|
|
|
;; this copied from lowdown's html-serialization-rules* because it is for
|
|
|
|
;; some reason not exported, so i can't just import it??
|
|
|
|
(*COMMENT* . ,(lambda (_t i) (list #\< "!--" i "--" #\>)))
|
|
|
|
;; ignore any #<unspecified> values in the tree
|
|
|
|
(*text* . ,(lambda (_t i) (if (unspecified? i) "" i)))
|
2022-12-16 12:28:55 -05:00
|
|
|
,@alist-conv-rules*))
|
|
|
|
|
2023-01-07 15:02:19 -05:00
|
|
|
;; reading in data from git commands ---------------------------------
|
2022-12-12 23:02:56 -05:00
|
|
|
|
2022-12-02 16:41:55 -05:00
|
|
|
(define (in-git-directory?)
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
(not (eof-object? (call-with-input-pipe "git rev-parse --git-dir" read-line))))
|
2022-12-02 16:41:55 -05:00
|
|
|
|
2023-01-07 15:02:19 -05:00
|
|
|
;; a weird hack to detect whether git considers a blob to be a binary or a text
|
|
|
|
;; file. works by requesting the numstat diff between it and the empty tree.
|
|
|
|
;; binary files give not a line count but '-' placeholders.
|
2022-12-16 12:28:55 -05:00
|
|
|
(define (git-file-is-text? source-file)
|
2022-12-09 22:46:08 -05:00
|
|
|
(not (equal?
|
2022-12-16 12:28:55 -05:00
|
|
|
"-\t-\t"
|
|
|
|
(call-with-input-pipe
|
2023-02-01 20:09:45 -05:00
|
|
|
(string-append "git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 --numstat HEAD -- " (qs source-file))
|
2022-12-25 17:35:31 -05:00
|
|
|
(cute read-line <> 4)))))
|
2022-12-09 22:46:08 -05:00
|
|
|
|
2022-12-02 16:41:55 -05:00
|
|
|
(define (git-repository->paths-list)
|
|
|
|
(call-with-input-pipe "git ls-tree -r --name-only HEAD" read-lines))
|
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
(define (git-file->string source-file)
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
(->
|
2023-02-01 20:09:45 -05:00
|
|
|
source-file
|
|
|
|
(qs)
|
|
|
|
((flip format) "git show HEAD:~a")
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
(call-with-input-pipe read-lines)
|
|
|
|
(string-intersperse "\n")))
|
|
|
|
|
2023-01-08 03:53:04 -05:00
|
|
|
;; the result of asking git for some configuration; #f if no result.
|
|
|
|
(define (git-config->string key)
|
|
|
|
(let [(result (call-with-input-pipe (string-append "git config " key) read-line))]
|
|
|
|
(if (eof-object? result) #f result)))
|
|
|
|
|
|
|
|
;; environment always takes precedent over git-config
|
|
|
|
(define (config key)
|
|
|
|
(or
|
|
|
|
(get-environment-variable (string-append "REPO2HTML_" (string-upcase key)))
|
|
|
|
(git-config->string (string-append "repo2html." (string-downcase key)))))
|
|
|
|
|
2023-01-07 15:02:19 -05:00
|
|
|
;; sxml generators for constructed pages ---------------------------------
|
2022-12-16 12:28:55 -05:00
|
|
|
|
2022-12-12 00:14:48 -05:00
|
|
|
(define (source->sxml source-file) ;; src/main.scm
|
|
|
|
(define-values (_ _ basename extension _)
|
|
|
|
(pathparts source-file))
|
2022-12-08 17:54:26 -05:00
|
|
|
(define (image-link)
|
2023-01-16 18:17:58 -05:00
|
|
|
`(p (img (@ (src (,(string-append basename extension)))))))
|
2022-12-08 17:54:26 -05:00
|
|
|
(define (plaintext)
|
2022-12-12 00:14:48 -05:00
|
|
|
`(pre ,(git-file->string source-file)))
|
2022-12-09 22:46:08 -05:00
|
|
|
(define (binary)
|
2022-12-12 00:14:48 -05:00
|
|
|
'(p "(Binary file)"))
|
2022-12-26 13:38:04 -05:00
|
|
|
(case (string->symbol extension)
|
|
|
|
((.md .markdown)
|
|
|
|
(handle-exceptions exn
|
|
|
|
(begin
|
|
|
|
(format (current-error-port) "Error parsing ~a\n" source-file)
|
|
|
|
`((p (b "There was an error parsing this file as Markdown."))
|
|
|
|
,(plaintext)))
|
|
|
|
(markdown->sxml (git-file->string source-file))))
|
|
|
|
((.jpg .jpeg .png .gif .webp .webm .apng .avif .svgz .ico)
|
|
|
|
(image-link))
|
|
|
|
((.svg)
|
|
|
|
(list (image-link) (plaintext)))
|
|
|
|
((.gz .pack .idx)
|
|
|
|
(binary))
|
|
|
|
(else
|
|
|
|
(if (git-file-is-text? source-file)
|
|
|
|
(plaintext)
|
2022-12-26 13:51:07 -05:00
|
|
|
(binary)))))
|
2022-12-12 00:14:48 -05:00
|
|
|
|
2022-12-18 12:59:59 -05:00
|
|
|
(define (filelist->sxml source-files-list relative-root)
|
2022-12-12 00:14:48 -05:00
|
|
|
`((h1 "Files")
|
|
|
|
((ul
|
2022-12-09 23:55:33 -05:00
|
|
|
,(map
|
2022-12-12 00:14:48 -05:00
|
|
|
(lambda (source-file)
|
2023-01-07 15:02:19 -05:00
|
|
|
`(li (a (@ (href ,(make-pathname relative-root source-file))) ,source-file)))
|
2022-12-12 00:14:48 -05:00
|
|
|
source-files-list)))))
|
|
|
|
|
|
|
|
(define (commits->sxml)
|
|
|
|
`((h1 "Commits")
|
|
|
|
(table
|
2023-01-07 15:02:19 -05:00
|
|
|
(tr
|
|
|
|
,@(map (lambda x `(th ,x)) '("Date" "Ref" "Log" "Author")))
|
2022-12-12 00:14:48 -05:00
|
|
|
,(map
|
|
|
|
(lambda (line)
|
|
|
|
(let-values (((date ref title author) (apply values (string-split line "\t"))))
|
|
|
|
`(tr (td ,date) (td ,ref) (td ,title) (td ,author))))
|
|
|
|
(call-with-input-pipe "git log --format=format:%as%x09%h%x09%s%x09%aN HEAD" read-lines)))))
|
|
|
|
|
|
|
|
(define (contributors->sxml)
|
|
|
|
`((h1 "Contributors")
|
|
|
|
(table
|
|
|
|
(tr (th "Author") (th "Commits"))
|
|
|
|
,(map
|
|
|
|
(lambda (line)
|
|
|
|
(let-values (((commits author) (apply values (string-split line "\t"))))
|
|
|
|
`(tr (td ,author) (td ,commits))))
|
|
|
|
(call-with-input-pipe "git shortlog -ns HEAD" read-lines)))))
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
|
2022-12-12 09:14:15 -05:00
|
|
|
(define (issueslist->sxml source-files-list)
|
|
|
|
`((h1 "Issues")
|
|
|
|
((ul
|
|
|
|
,(filter-map
|
|
|
|
(lambda (source-file)
|
|
|
|
(and
|
|
|
|
(string-prefix? "ISSUES/" source-file)
|
2023-01-07 15:02:19 -05:00
|
|
|
`(li (a (@ (href ,source-file))
|
2022-12-12 09:14:15 -05:00
|
|
|
,(->
|
2023-02-01 20:09:45 -05:00
|
|
|
(string-append "HEAD:" source-file)
|
|
|
|
(qs)
|
|
|
|
((flip format) "git show ~a")
|
2022-12-12 09:14:15 -05:00
|
|
|
(call-with-input-pipe read-line)
|
2023-02-01 20:09:45 -05:00
|
|
|
((lambda (x) (if (eof-object? x) (pathname-strip-directory source-file) x)))
|
2022-12-12 09:14:15 -05:00
|
|
|
(string-trim (string->char-set "# ")))))))
|
|
|
|
source-files-list)))))
|
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
;; used by ersatz writer
|
|
|
|
(define (alist->tvals vars)
|
|
|
|
(map (lambda (pair)
|
|
|
|
`(,(car pair) . ,(sexpr->tvalue (cdr pair)))) vars))
|
|
|
|
|
|
|
|
;; this version uses a jinja-style template via ersatz
|
|
|
|
(define (make-template-writer-ersatz templates-directory #!optional vars)
|
|
|
|
(define template (statements-from-file (template-std-env search-path: (list templates-directory)) "default.html"))
|
|
|
|
(lambda (output-filename body-sxml #!optional newvars)
|
|
|
|
;; create destination directory if needed
|
|
|
|
(if-let (destination-directory (pathname-directory output-filename))
|
|
|
|
(create-directory destination-directory #t)
|
|
|
|
'())
|
|
|
|
|
2022-12-22 17:53:13 -05:00
|
|
|
(let* (;; vars = global vars + file-specific vars
|
|
|
|
(vars (alist-merge vars (or newvars '())))
|
2023-01-07 15:02:19 -05:00
|
|
|
(adjust-relative (unless-equals (alist-ref 'relative_root vars) "html/"))
|
2022-12-22 17:53:13 -05:00
|
|
|
;; render the sxml to a html string that we can hand to the template
|
2022-12-16 12:28:55 -05:00
|
|
|
(body-html
|
|
|
|
(with-output-to-string
|
|
|
|
(lambda ()
|
2023-01-07 15:02:19 -05:00
|
|
|
(SXML->HTML (pre-post-order* body-sxml (sxml-html-rules adjust-relative))))))
|
2022-12-22 17:53:13 -05:00
|
|
|
;; vars = vars + body k/v pair
|
|
|
|
(vars (alist-cons 'content body-html vars)))
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
(with-output-to-file output-filename
|
2022-12-12 00:14:48 -05:00
|
|
|
(lambda ()
|
2022-12-16 12:28:55 -05:00
|
|
|
(display (eval-statements template models: (alist->tvals vars))))))))
|
|
|
|
|
2022-12-18 12:56:47 -05:00
|
|
|
;; main program ------------------------------------------------------------------------------
|
2022-12-16 12:28:55 -05:00
|
|
|
|
|
|
|
(define (generate-html-files html-repo-path templates-directory)
|
2022-12-22 17:53:13 -05:00
|
|
|
;; git automatically updates this hash when you checkout/pull/etc.
|
2022-12-18 12:59:59 -05:00
|
|
|
(let* ((version-ident "$Id$")
|
|
|
|
(source-files-list (git-repository->paths-list))
|
2023-01-08 03:53:04 -05:00
|
|
|
(forge-root (string-append (string-chomp (or (config "forgeroot") "") "/") "/"))
|
2023-01-08 12:27:39 -05:00
|
|
|
(repository-path (or (config "path")
|
|
|
|
(and (not (equal? forge-root "/"))
|
|
|
|
(string-prefix? forge-root html-repo-path)
|
|
|
|
(string-drop html-repo-path (string-length forge-root)))
|
|
|
|
(pathname-strip-directory html-repo-path)))
|
2022-12-18 12:59:59 -05:00
|
|
|
(template-alist
|
|
|
|
`(;; variables provided to template at all times. beware: ersatz
|
|
|
|
;; templates break if you attempt to use a variable with a hyphen.
|
|
|
|
|
|
|
|
;; the list of all files in the git repo
|
|
|
|
(source_files_list . ,source-files-list)
|
2023-01-08 03:53:04 -05:00
|
|
|
;; the description of the repo, taken from: env, config, cgit-like
|
2022-12-18 12:59:59 -05:00
|
|
|
;; description file
|
2023-01-08 03:53:04 -05:00
|
|
|
(repository_description . ,(or (config "description")
|
|
|
|
(if-let (f (file-exists? "description"))
|
|
|
|
(with-input-from-file f read-lines) #f)
|
|
|
|
""))
|
|
|
|
;; the name of the repo, which is usually but not necessarily the
|
|
|
|
;; same as its directory name (and last path element of the url)
|
|
|
|
(repository_name . ,(or (config "name")
|
|
|
|
(-> html-repo-path
|
|
|
|
(string-chomp ".git")
|
|
|
|
(pathname-strip-directory))))
|
|
|
|
;; the path from the forge root to the repository
|
2023-01-08 12:27:39 -05:00
|
|
|
(repository_path . ,repository-path)
|
|
|
|
;; the repository_path with the last path element removed
|
|
|
|
(repository_path_parent . ,(or (pathname-directory repository-path) ""))
|
|
|
|
;; the repository_path_parent as a list of path components
|
|
|
|
(repository_ancestors . ,(or (string-split (or (pathname-directory repository-path) "") "/") '()))
|
2023-01-08 03:53:04 -05:00
|
|
|
;; the first README file found among these, if any.
|
|
|
|
(readme_file . ,(find (cut member <> source-files-list)
|
|
|
|
'("README.md" "README" "README.txt")))
|
|
|
|
;; the first LICENSE file found among these, if any.
|
|
|
|
(license_file . ,(find (cut member <> source-files-list)
|
|
|
|
'("LICENSE.md" "LICENSE" "LICENSE.txt")))
|
2022-12-18 12:59:59 -05:00
|
|
|
;; the string "ISSUES" if any files exist in ISSUES/
|
2023-01-08 03:53:04 -05:00
|
|
|
(issues_file . ,(and (find (cut string-prefix? "ISSUES/" <>) source-files-list) "ISSUES"))
|
|
|
|
(repo2html_version . ,(if (equal? version-ident (list->string '(#\$ #\I #\d #\$)))
|
|
|
|
""
|
|
|
|
(substring* version-ident 5 12)))
|
2022-12-18 12:59:59 -05:00
|
|
|
))
|
2022-12-16 12:28:55 -05:00
|
|
|
(write-with-template
|
2022-12-18 12:56:47 -05:00
|
|
|
(make-template-writer-ersatz templates-directory template-alist)))
|
2022-12-18 12:59:59 -05:00
|
|
|
(define html-path (make-pathname html-repo-path "html"))
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
|
|
|
|
(create-directory html-repo-path #t)
|
2022-12-09 02:15:03 -05:00
|
|
|
;; special files
|
2022-12-18 12:59:59 -05:00
|
|
|
(write-with-template (make-pathname html-path "files" "html") (filelist->sxml source-files-list ""))
|
|
|
|
(write-with-template (make-pathname html-path "contributors" "html") (contributors->sxml))
|
|
|
|
(write-with-template (make-pathname html-path "commits" "html") (commits->sxml))
|
2022-12-09 02:15:03 -05:00
|
|
|
;; htmlified repo contents
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
(for-each
|
|
|
|
(lambda (source-file)
|
2022-12-16 12:28:55 -05:00
|
|
|
(->> source-file
|
|
|
|
(pathparts)
|
|
|
|
(define-values (root elements basename extension relative-root)))
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
(write-with-template
|
2022-12-18 12:59:59 -05:00
|
|
|
(make-pathname html-path source-file "html")
|
2022-12-16 12:28:55 -05:00
|
|
|
(source->sxml source-file)
|
|
|
|
`(;; additional per-page variables provided to template
|
|
|
|
(source_file . ,source-file)
|
|
|
|
(root . ,root)
|
|
|
|
(elements . ,elements)
|
|
|
|
(basename . ,basename)
|
|
|
|
(extension . ,extension)
|
|
|
|
(relative_root . ,relative-root)
|
|
|
|
))
|
2022-12-18 12:59:59 -05:00
|
|
|
;; if it's an image, also write it verbatim to output directory
|
massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?
and whew it kindof got away from me
i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!
anyway let's see if i can summarize the changes:
- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
annoying, in that it only returns a string if it makes no changes, but
if it does, it returns a list of strings. it expects to be passed to
one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
functions
- simple command line use: from any git work-tree OR bare repo, run
repo2html /path/to/www/output/repo-foo-bar and it will create that
directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
- changed env var names to have REPO2HTML_ prefix
- better repo name detection and automatic caching of it in git config
- moved the post-receive-specific logic to avoid generating if we're
not updating HEAD into the post-receive hook itself, along with some
status messages
- checked directory permissions in the hook so it doesn't even attempt
to run repo2html and avoids a crash
2022-12-07 04:00:52 -05:00
|
|
|
(case (string->symbol (or (pathname-extension source-file) ""))
|
|
|
|
((jpg jpeg png gif webp webm svg apng avif svgz ico)
|
2022-12-07 19:17:49 -05:00
|
|
|
(system (format "git show HEAD:~a > ~a"
|
2023-02-01 20:09:45 -05:00
|
|
|
(qs source-file)
|
|
|
|
(make-pathname html-path (qs source-file)))))))
|
2022-12-09 02:15:03 -05:00
|
|
|
source-files-list)
|
2022-12-18 12:59:59 -05:00
|
|
|
;; if README.md, README, or README.txt exists, regenerate it as index.html.
|
|
|
|
;; otherwise regenerate files.html as index.html.
|
|
|
|
(write-with-template
|
|
|
|
(make-pathname html-repo-path "index" "html")
|
|
|
|
(if-let (readme-file
|
|
|
|
(alist-ref 'readme_file template-alist))
|
|
|
|
(source->sxml readme-file)
|
2023-02-01 23:26:10 -05:00
|
|
|
(filelist->sxml source-files-list ""))
|
2022-12-18 12:59:59 -05:00
|
|
|
;; TODO: do we need the full set of template variables defined here?
|
|
|
|
;; if so maybe this and the set above should be lifted out somewhere
|
|
|
|
`((relative_root . "html/")))
|
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
;; if the ISSUES directory got created, write out an index file for the
|
|
|
|
;; stuff in there.
|
2022-12-18 12:59:59 -05:00
|
|
|
(when (file-exists? (make-pathname html-path "ISSUES"))
|
|
|
|
(write-with-template (make-pathname html-path "ISSUES" "html") (issueslist->sxml source-files-list)))))
|
2022-12-02 16:41:55 -05:00
|
|
|
|
2022-12-18 12:56:47 -05:00
|
|
|
(define (main #!optional html-repo-path templates-directory)
|
2022-12-02 16:41:55 -05:00
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
(unless html-repo-path
|
|
|
|
(bail "please specify a destination directory for html files"))
|
2022-12-04 15:17:31 -05:00
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
(unless (in-git-directory?)
|
|
|
|
(bail "woops this isn't a git directory"))
|
2022-12-04 15:17:31 -05:00
|
|
|
|
2022-12-18 12:56:47 -05:00
|
|
|
(unless templates-directory
|
|
|
|
(bail "please specify the directory containing the templates.\nnote: built-in sxml templates have been removed."))
|
|
|
|
|
2023-01-08 03:53:04 -05:00
|
|
|
(generate-html-files (string-chomp html-repo-path "/") templates-directory))
|
2022-12-04 15:17:31 -05:00
|
|
|
|
2022-12-16 12:28:55 -05:00
|
|
|
(apply main (command-line-arguments))
|