;; 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
lowdown
(chicken string)
(chicken port)
(chicken io)
(chicken process)
(chicken process-context)
(chicken format)
(chicken pathname)
(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 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 DESCRIPTION (or (get-environment-variable "GIT_WWW_DESCRIPTION") "my git repositories"))
(define H1 (or (get-environment-variable "GIT_WWW_H1") "git.example.com"))
(define (populate-html-template body)
#<#string-block
\n" link-url source-file)
(generate-list-of-files (cdr source-files-list))))))
(define (generate-source-file source-file) ;; src/main.scm
(let* ((source-file-directory (pathname-directory source-file)) ;; src or #f
(output-directory (if source-file-directory
(make-pathname *repository-directory* source-file-directory) ;; //src
*repository-directory*))) ;; /
;; 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
;; matches up with the path of the source file.
;; i guess another reason to do this is to avoid conflicts with files that
;; have the same name, but exist in different directories.
(create-directory output-directory #t)
(write-file
(make-pathname output-directory (pathname-strip-directory source-file) "html")
(populate-html-template (string-append "