cleaned up main.scm

- removed old comments
- moved todos and nice-to-haves into the README.md's todos and hopes
- changed gobally mutated variables to be global constants. originally
  these were mutated because the code was structured differently, and
  allowed an option argument, specifying which bare git repo to use, but
  i removed that, and forgot to remove and change the cruft
This commit is contained in:
m455 2022-12-02 23:31:54 -05:00
parent 1165ba3342
commit 0216eacef6
2 changed files with 23 additions and 57 deletions

View file

@ -47,8 +47,14 @@ TODO
## todos ## todos
TODO - ☐ nav link: License (look for LICENSE file)
- ☐ nav link: Contributors
## hopes ## hopes
- ☐ clickable line numbers in source files
- ☐ render images
- ☐ make repos with more files and directories less daunting (recursively generate a files list page for each directory in a repo?)
- ☐ nav link: Releases
TODO TODO

View file

@ -1,35 +1,3 @@
;; how to use this script
;; 1. cd into a bare git repository
;; 2. run the following, changing any values you want:
;; export GIT_WWW=/var/www/git/ GIT_WWW_CLONE_URL=git://git.m455.casa GIT_WWW_TITLE=git.m455.casa GIT_WWW_DESCRIPTION="m455's git repositories" GIT_WWW_H1=git.m455.casa; csi -s ../main.scm
;; i figured i would use environment variables instead of a config file,
;; because folks are just going to run this as a post-receive hook anyway, so
;; why not all just configure it all in the post-receive hook like so?
;; (assuming git-www is in your $PATH, and assuming git-www is a compiled
;; version of git-www.scm):
;; ---------------------------------
;; #!/bin/sh
;; export GIT_WWW=/var/www/git/
;; export GIT_WWW_CLONE_URL=git://git.m455.casa
;; export GIT_WWW_TITLE=git.m455.casa
;; export GIT_WWW_DESCRIPTION="m455's git repositories"
;; export GIT_WWW_H1=git.m455.casa
;; git-www
;; ---------------------------------
;; TODO:
;; [x] replace all repository-name with *repository-name*
;; [x] replace all repository-directory with *repository-directory*
;; [x] remove all passed around parameters for repo name and directory
;; [x] move html-body-contents into final html-template format except use
;; string translate for named variables in the html-template
;; Nice-to-haves:
;; [ ] nav link: License (look for LICENSE file)
;; [ ] nav link: Contributors
;; [ ] nav link: Releases
;; [ ] clickable line numbers in source files
;; [ ] render images
;; [ ] make repos with more files and directories less daunting (recursively generate a files list page for each directory in a repo?)
(import utf8 (import utf8
lowdown lowdown
(chicken string) (chicken string)
@ -41,17 +9,15 @@
(chicken pathname) (chicken pathname)
(chicken file)) (chicken file))
;; decided to make these two buggers globals because i passed them around
;; between functions so much
(define *repository-name* #f)
(define *repository-directory* #f)
(define WEB-DIRECTORY (or (get-environment-variable "GIT_WWW") "/var/www/git")) (define WEB-DIRECTORY (or (get-environment-variable "GIT_WWW") "/var/www/git"))
(define CLONE-URL (or (get-environment-variable "GIT_WWW_CLONE_URL") "git://git.example.com")) (define CLONE-URL (or (get-environment-variable "GIT_WWW_CLONE_URL") "git://git.example.com"))
(define TITLE (or (get-environment-variable "GIT_WWW_TITLE") "my git repositories")) (define TITLE (or (get-environment-variable "GIT_WWW_TITLE") "my git repositories"))
(define DESCRIPTION (or (get-environment-variable "GIT_WWW_DESCRIPTION") "my git repositories")) (define DESCRIPTION (or (get-environment-variable "GIT_WWW_DESCRIPTION") "my git repositories"))
(define H1 (or (get-environment-variable "GIT_WWW_H1") "git.example.com")) (define H1 (or (get-environment-variable "GIT_WWW_H1") "git.example.com"))
(define REPOSITORY-NAME (pathname-strip-directory (current-directory)))
(define REPOSITORY-DIRECTORY (make-pathname WEB-DIRECTORY REPOSITORY-NAME))
(define (populate-html-template body) (define (populate-html-template body)
#<#string-block #<#string-block
<!DOCTYPE html> <!DOCTYPE html>
@ -87,11 +53,11 @@ hr {
</head> </head>
<body> <body>
<h1>#{H1}</h1> <h1>#{H1}</h1>
<h2>#{*repository-name*}</h2> <h2>#{REPOSITORY-NAME}</h2>
<p>clone url: #{CLONE-URL}/#{*repository-name*}</p> <p>clone url: #{CLONE-URL}/#{REPOSITORY-NAME}</p>
<nav> <nav>
<a href="/#{*repository-name*}/index.html">about</a> <a href="/#{REPOSITORY-NAME}/index.html">about</a>
<a href="/#{*repository-name*}/files.html">files</a> <a href="/#{REPOSITORY-NAME}/files.html">files</a>
</nav> </nav>
<hr> <hr>
#{body} #{body}
@ -108,10 +74,6 @@ string-block
#t #t
#f)) #f))
(define (get-repository-name)
(pathname-strip-directory (current-directory)))
; (call-with-input-pipe "git config --get remote.origin.url" read-line)))
(define (git-repository->paths-list) (define (git-repository->paths-list)
(call-with-input-pipe "git ls-tree -r --name-only HEAD" read-lines)) (call-with-input-pipe "git ls-tree -r --name-only HEAD" read-lines))
@ -144,8 +106,8 @@ string-block
(define (generate-source-file source-file) ;; src/main.scm (define (generate-source-file source-file) ;; src/main.scm
(let* ((source-file-directory (pathname-directory source-file)) ;; src or #f (let* ((source-file-directory (pathname-directory source-file)) ;; src or #f
(output-directory (if source-file-directory (output-directory (if source-file-directory
(make-pathname *repository-directory* source-file-directory) ;; <WEB-DIRECTORY>/<repository-name>/src (make-pathname REPOSITORY-DIRECTORY source-file-directory) ;; <WEB-DIRECTORY>/<repository-name>/src
*repository-directory*))) ;; <WEB-DIRECTORY>/<repository-name> REPOSITORY-DIRECTORY))) ;; <WEB-DIRECTORY>/<repository-name>
;; create directories that mimic the path of the source file, so when ;; create directories that mimic the path of the source file, so when
;; someone clicks a link to view the contents of a source file, the URL ;; someone clicks a link to view the contents of a source file, the URL
;; matches up with the path of the source file. ;; matches up with the path of the source file.
@ -176,23 +138,21 @@ string-block
(populate-html-template (md->html (git-file->string "README.md"))))) (populate-html-template (md->html (git-file->string "README.md")))))
(define (generate-repository-directory) (define (generate-repository-directory)
(if (directory-exists? *repository-directory*) (if (directory-exists? REPOSITORY-DIRECTORY)
(begin (delete-directory *repository-directory* #t) (begin (delete-directory REPOSITORY-DIRECTORY #t)
(create-directory *repository-directory* #t)) (create-directory REPOSITORY-DIRECTORY #t))
(create-directory *repository-directory* #t))) (create-directory REPOSITORY-DIRECTORY #t)))
(define (generate-html-files) (define (generate-html-files)
(let ((source-files-list (git-repository->paths-list))) (let ((source-files-list (git-repository->paths-list)))
(generate-repository-directory) (generate-repository-directory)
(generate-readme-file (make-pathname *repository-directory* "index.html")) (generate-readme-file (make-pathname REPOSITORY-DIRECTORY "index.html"))
(generate-files-file (make-pathname *repository-directory* "files.html") source-files-list) (generate-files-file (make-pathname REPOSITORY-DIRECTORY "files.html") source-files-list)
(generate-source-files source-files-list))) (generate-source-files source-files-list)))
(define (if-git-directory-generate-html-files) (define (if-git-directory-generate-html-files)
(if (in-git-directory?) (if (in-git-directory?)
(begin (set! *repository-name* (get-repository-name)) (generate-html-files)
(set! *repository-directory* (make-pathname WEB-DIRECTORY *repository-name*))
(generate-html-files))
(print "woops that's not a git directory"))) (print "woops that's not a git directory")))
(define (main args) (define (main args)