From 0216eacef656cc454032f8a17d2aff84b4668172 Mon Sep 17 00:00:00 2001 From: m455 Date: Fri, 2 Dec 2022 23:31:54 -0500 Subject: [PATCH] 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 --- README.md | 8 ++++++- main.scm | 72 +++++++++++++------------------------------------------ 2 files changed, 23 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index cf267fc..af40924 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,14 @@ TODO ## todos -TODO +- ☐ nav link: License (look for LICENSE file) +- ☐ nav link: Contributors ## 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 diff --git a/main.scm b/main.scm index b65b899..7c7b99e 100644 --- a/main.scm +++ b/main.scm @@ -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 lowdown (chicken string) @@ -41,17 +9,15 @@ (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 REPOSITORY-NAME (pathname-strip-directory (current-directory))) +(define REPOSITORY-DIRECTORY (make-pathname WEB-DIRECTORY REPOSITORY-NAME)) + (define (populate-html-template body) #<#string-block @@ -87,11 +53,11 @@ hr {

#{H1}

-

#{*repository-name*}

-

clone url: #{CLONE-URL}/#{*repository-name*}

+

#{REPOSITORY-NAME}

+

clone url: #{CLONE-URL}/#{REPOSITORY-NAME}


#{body} @@ -108,10 +74,6 @@ string-block #t #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) (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 (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*))) ;; / + (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. @@ -176,23 +138,21 @@ string-block (populate-html-template (md->html (git-file->string "README.md"))))) (define (generate-repository-directory) - (if (directory-exists? *repository-directory*) - (begin (delete-directory *repository-directory* #t) - (create-directory *repository-directory* #t)) - (create-directory *repository-directory* #t))) + (if (directory-exists? REPOSITORY-DIRECTORY) + (begin (delete-directory REPOSITORY-DIRECTORY #t) + (create-directory REPOSITORY-DIRECTORY #t)) + (create-directory REPOSITORY-DIRECTORY #t))) (define (generate-html-files) (let ((source-files-list (git-repository->paths-list))) (generate-repository-directory) - (generate-readme-file (make-pathname *repository-directory* "index.html")) - (generate-files-file (make-pathname *repository-directory* "files.html") source-files-list) + (generate-readme-file (make-pathname REPOSITORY-DIRECTORY "index.html")) + (generate-files-file (make-pathname REPOSITORY-DIRECTORY "files.html") source-files-list) (generate-source-files source-files-list))) (define (if-git-directory-generate-html-files) (if (in-git-directory?) - (begin (set! *repository-name* (get-repository-name)) - (set! *repository-directory* (make-pathname WEB-DIRECTORY *repository-name*)) - (generate-html-files)) + (generate-html-files) (print "woops that's not a git directory"))) (define (main args)