check file existence in source-files-list not cwd

added source-files-list to populate-html-template. kindof dislike having
so many variables passed to a function but i also kindof dislike global
variables; not sure how to make this prettier yet. but this solves the
bug i introduced in my last commit where the nav links were broken when
used as a githook.
This commit is contained in:
pho4cexa 2022-12-09 08:00:07 -08:00 committed by m455
parent c645880703
commit 626a84a76e
2 changed files with 10 additions and 7 deletions

View file

@ -8,6 +8,9 @@
Assuming the current directory is a Git repository, this command populates *DESTINATION* with HTML files that provide a web-browsable view of the contents of the git repository.
Note: changes must be at least committed before they will appear in the HTML output.
More precisely: the HTML output represents the state of the HEAD commit, not that of the current work-tree (if any).
You may also cause this directory to be automatically updated upon every `git push`, by invoking *repo2html* as a Git *post-receive hook*.
## features

View file

@ -19,7 +19,7 @@
(define DESCRIPTION (or (get-environment-variable "REPO2HTML_DESCRIPTION") "my git repositories"))
(define H1 (or (get-environment-variable "REPO2HTML_H1") "git.example.com"))
(define (populate-html-template repository-name source-file display-body-thunk)
(define (populate-html-template repository-name source-files-list source-file display-body-thunk)
(define-values (source-directory source-filename source-extension)
(decompose-pathname source-file))
(define-values (base-origin base-directory directory-elements)
@ -75,14 +75,14 @@ hr {
<h2>#{repository-name}</h2>
<p>clone url: #{CLONE-URL}/#{repository-name}</p>
<nav>
#(if (or (file-exists? "README")
(file-exists? "README.md")
(file-exists? "README.txt"))
#(if (or (member "README" source-files-list)
(member "README.md" source-files-list)
(member "README.txt" source-files-list))
(string-append "<a href=\"" relative-root "index.html\">about</a>"))
<a href="#{relative-root}files.html">files</a>
#(cond ((file-exists? "LICENSE")
#(cond ((member "LICENSE" source-files-list)
(string-append "<a href=\"" relative-root "LICENSE.html\">license</a>"))
((file-exists? "LICENSE.md")
((member "LICENSE.md" source-files-list)
(string-append "<a href=\"" relative-root "LICENSE.md.html\">license</a>")))
<a href="#{relative-root}contributors.html">contributors</a>
</nav>
@ -181,7 +181,7 @@ string-block
(when destination-directory
(create-directory (make-pathname html-repo-path destination-directory) #t)))
(with-output-to-file (make-pathname html-repo-path filename)
(lambda () (populate-html-template repository-name filename display-body-thunk))))
(lambda () (populate-html-template repository-name source-files-list filename display-body-thunk))))
(create-directory html-repo-path #t)
;; special files