From d106bf4ca6bd0c9370d5c1032b7b7f80ff723792 Mon Sep 17 00:00:00 2001 From: pho4cexa Date: Fri, 9 Dec 2022 19:46:08 -0800 Subject: [PATCH] detect (er, ask git) if files are text or binary (ty m455 & acdw!) also remove unused procedure display-readme-html --- README.md | 1 - main.scm | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bad1704..fa01d6f 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/main.scm b/main.scm index fd2b48b..b5cdc32 100755 --- a/main.scm +++ b/main.scm @@ -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 "
")
     (display-escaped-html (git-file->string source-file))
     (display "
")) + (define (binary) + (display "

(Binary file)

")) (format #t "

~a

" 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 "

(Binary file)

")) + (binary)) (else - (plaintext)))) + (if (is-text? source-file) + (plaintext) + (binary))))) (define (display-files-html source-files-list) (display "\n")) -(define (display-readme-html) - (markdown->html (git-file->string "README.md"))) - (define (display-contributors-html) (SXML->HTML `((h1 "Contributors")