detect (er, ask git) if files are text or binary (ty m455 & acdw!)

also remove unused procedure display-readme-html
This commit is contained in:
pho4cexa 2022-12-09 19:46:08 -08:00 committed by m455
parent a97c673158
commit d106bf4ca6
2 changed files with 13 additions and 6 deletions

View file

@ -57,7 +57,6 @@ TODO
- **documenation**: scope the readme audience to folks who kind of know what they're doing with servers
- **documentation/feature**: use post-update rather than post-receive hook for simplicity
- **documentation**: also describe use with post-commit hook
- **feature**: need better detection and rendering of binary files
- **feature**: multi-page or collapse-able files list
- **feature**: commit log
- **feature**: branches and releases (tags)

View file

@ -102,6 +102,13 @@ string-block
(define (in-git-directory?)
(not (eof-object? (call-with-input-pipe "git rev-parse --git-dir" read-line))))
(define (is-text? path)
(not (equal?
"-\t-\t"
(call-with-input-pipe
(string-append "git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 --numstat HEAD -- " path)
(lambda (port) (read-line port 4))))))
(define (git-repository->paths-list)
(call-with-input-pipe "git ls-tree -r --name-only HEAD" read-lines))
@ -125,6 +132,8 @@ string-block
(display "<pre>")
(display-escaped-html (git-file->string source-file))
(display "</pre>"))
(define (binary)
(display "<p>(Binary file)</p>"))
(format #t "<p id=\"file-path\">~a</p>" source-file)
(case (string->symbol (or source-extension source-filename))
;; markdown files get rendered in-place, unless there's an error, in which
@ -143,9 +152,11 @@ string-block
((svg)
(image-link) (plaintext))
((gz pack idx)
(display "<p>(Binary file)</p>"))
(binary))
(else
(plaintext))))
(if (is-text? source-file)
(plaintext)
(binary)))))
(define (display-files-html source-files-list)
(display "<ul>\n")
@ -155,9 +166,6 @@ string-block
source-files-list)
(display "</ul>\n"))
(define (display-readme-html)
(markdown->html (git-file->string "README.md")))
(define (display-contributors-html)
(SXML->HTML
`((h1 "Contributors")