repo2html/post-receive
pho4cexa 50bbb3686d massive changes incl. support for images, markdown
i started this off by trying to learn more about how scheme does file
i/o. it seems like many of its functions just expect you'll want them to
write to (current-output-port) instead of returning a string. so i
thought, i wonder what it would look like if i tweak these content
generator functions to just (display) their stuff, and
call (with-output-to-file) and apply the html template each time i call
them?

and whew it kindof got away from me

i totally understand if you feel like this is an unpleasant overhaul of
your whole project and don't want to merge this change!

anyway let's see if i can summarize the changes:

- image support!!
- svg image support!! it shows both the svg and its source code!
- markdown support; we now render all .md files instead of showing source
- using string->goodHTML instead of clean-html. turns out, it's a little
  annoying, in that it only returns a string if it makes no changes, but
  if it does, it returns a list of strings. it expects to be passed to
  one of the other functions in the sxml library, so that's what i do.
- moved "wrap the template" outside of various "generate content"
  functions
- simple command line use: from any git work-tree OR bare repo, run
  repo2html /path/to/www/output/repo-foo-bar and it will create that
  directory and use "repo-foo-bar" as the repo name.
- made our example post-receive a bit more robust
  - changed env var names to have REPO2HTML_ prefix
  - better repo name detection and automatic caching of it in git config
  - moved the post-receive-specific logic to avoid generating if we're
    not updating HEAD into the post-receive hook itself, along with some
    status messages
  - checked directory permissions in the hook so it doesn't even attempt
    to run repo2html and avoids a crash
2022-12-07 14:51:23 -05:00

55 lines
1.9 KiB
Bash
Executable file

#!/bin/sh
# - place this file in the 'hooks' directory of a bare git repository
# - this assumes that repo2html is in your path
# The toplevel path containing directories of static pages
[ "$REPO2HTML_PREFIX" ] || export REPO2HTML_PREFIX=/var/www/git
# The toplevel clone url for repos.
export REPO2HTML_CLONE_URL=git://git.example.com
export REPO2HTML_TITLE=git.example.com
export REPO2HTML_DESCRIPTION="sherry's git repositories"
export REPO2HTML_H1=git.example.com
# hueristic attempt to detect a reasonable default for the name of this repo
# you may want to adjust this if you have e.g. sub-directories containing repos
# whose structure you want to preserve on the webserver.
if repo_name="$(git config repo2html.dirname)"; then
: # repo name from git config; do nothing else
elif [ "$(git rev-parse --is-bare-repository)" = "true" ]; then
# bare /foo/bar/baz/myrepo.git -> myrepo
repo_name="$(basename "$(pwd)" .git)"
git config repo2html.dirname "$repo_name"
else
# /foo/bar/baz/myrepo/.git -> myrepo
repo_name="$(basename "$(dirname "$(pwd)")")"
git config repo2html.dirname "$repo_name"
fi
# only generate if default branch is modified
headref="$(git symbolic-ref -q HEAD)"
while read -r _ _ ref
do [ "$ref" = "$headref" ] && go=1
done
if [ "$go" ]; then
echo "$headref was updated; regenerating HTML at: $REPO2HTML_PREFIX/$repo_name"
else
echo "($headref was not updated so HTML will not be regenerated.)"
exit 0
fi
# check to see if we can even write to the specified directory
if mkdir -p "$REPO2HTML_PREFIX/$repo_name" && \
[ -x "$REPO2HTML_PREFIX/$repo_name" ] && \
[ -w "$REPO2HTML_PREFIX/$repo_name" ]
then
: # we can write to the directory; seems good
else
echo "Error: can't generate HTML due to insufficient permissions on path:"
echo " $REPO2HTML_PREFIX/$repo_name"
echo "Set REPO2HTML_PREFIX in the environment or this script:"
echo " $0"
exit 1
fi
repo2html "$REPO2HTML_PREFIX/$repo_name"