aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-09-08 15:37:19 -0300
committerEuAndreh <eu@euandre.org>2021-09-08 15:39:30 -0300
commit754a1d2c3100e2fc533bfd4a23735ba4448ebe0a (patch)
treeed8623ed4af82b3e3c27ec7b4c83740c3c258b0e
parentsrc/gistatic.in: Initial sh version (diff)
downloadgistatic-754a1d2c3100e2fc533bfd4a23735ba4448ebe0a.tar.gz
gistatic-754a1d2c3100e2fc533bfd4a23735ba4448ebe0a.tar.xz
src/gistatic.in: Finish refs page with signatures, start commit pages
- actually implement HTML escaping; - include cached_run for (hopefully) reusing across HTML generating functions; - include the repository name on the $CACHE_DIR; - use the existence of a .asc file to decide on which HTML to output on the refs page; - implement all FIXMEs but the WIP one on the commit HTML generation.
-rwxr-xr-xsrc/gistatic.in74
1 files changed, 54 insertions, 20 deletions
diff --git a/src/gistatic.in b/src/gistatic.in
index f18742a..589d2f6 100755
--- a/src/gistatic.in
+++ b/src/gistatic.in
@@ -88,11 +88,15 @@ case "$(get_lang)" in
;;
esac
+
+#
# Utilities
+#
escape() {
- # FIXME: HTML escape
- echo "$1"
+ echo "$1" |
+ sed -e 's|&|\&amp;|g;s|<|\&lt;|g;s|>|\&gt;|g;s|"|\&quot;|g' \
+ -e "s|'|\&#39|g"
}
realpath() {
@@ -102,7 +106,9 @@ realpath() {
}
-# Helpers
+#
+# Documentation functions
+#
usage() {
printf '%s\n' "$MSG_USAGE"
@@ -116,6 +122,11 @@ version() {
printf '@NAME@-@VERSION@ @DATE@\n'
}
+
+#
+# Template strings
+#
+
print_logo() {
cat <<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
@@ -381,7 +392,6 @@ index_write() {
print_repo_refs() {
repo="$1"
description="$2"
- show_signature="$3"
cat <<EOF
<!DOCTYPE html>
<html lang="$(escape "$MSG_LANGNAME")">
@@ -496,8 +506,8 @@ EOF
<tbody>
EOF
- for tag in $(git tag); do
- if [ "$show_signature" = true ]; then
+ for tag in $(git tag | sed '1!G;h;$!d'); do
+ if [ -e "$CACHE_DIR/tarballs/$repo-$tag.tar.gz.asc" ]; then
tarball_link="(<a href=\"tarballs/$(escape "$repo")-$(escape "$tag").tar.gz\">tarball</a>,
<a href=\"tarballs/$(escape "$repo")-$(escape "$tag").tar.gz.asc\">sig</a>)"
else
@@ -536,7 +546,16 @@ EOF
EOF
}
+print_formatted_diff() {
+ sha="$1"
+ printf '<pre>'
+ git show -p "$sha"
+ printf '</pre>\n'
+}
+
print_repo_commit_page() {
+ sha="$2"
+ summary="$(git log -1 --format=%B "$sha")"
cat <<EOF
<!DOCTYPE html>
<html lang="$(escape "$MSG_LANGNAME")">
@@ -548,7 +567,7 @@ print_repo_commit_page() {
<link rel="stylesheet" type="text/css" href="../style.css" />
<link rel="alternate" type="application/atom+xml" href="../commits.xml" title="$(escape "$repo") - $(escape "$MSG_COMMIT_FEED")" hreflang="$(escape "$MSG_LANGNAME")" />
<link rel="alternate" type="application/atom+xml" href="../tags.xml" title="$(escape "$repo") - $(escape "$MSG_TAGS_FEED")" hreflang="$(escape "$MSG_LANGNAME")" />
- <title>$(escape "$repo") - FIXME put content here</title>
+ <title>$(escape "$repo")@$(escape "$sha") - $(escape "$summary")</title>
</head>
<body>
<header>
@@ -592,7 +611,7 @@ print_repo_commit_page() {
<hr />
</header>
<main>
- CODE HR
+$(print_formatted_diff "$sha")
</main>
<footer>
<hr />
@@ -605,6 +624,22 @@ print_repo_commit_page() {
EOF
}
+
+cached_run() {
+ TARGET_PATH="$1"
+ shift # drop $TARGET_PATH
+ shift # drop --
+
+ if [ -e "$OUTDIR/$TARGET_PATH" ]; then
+ echo "$OUTDIR/$TARGET_PATH"
+ return
+ fi
+ if [ ! -e "$CACHE_DIR/$TARGET_PATH" ]; then
+ "$@"
+ fi
+ cp "$CACHE_DIR/$TARGET_PATH" "$OUTDIR/$TARGET_PATH"
+}
+
repo_tarballs_write() {
repo="$1"
mkdir -p "$OUTDIR/tarballs" "$CACHE_DIR/tarballs"
@@ -615,17 +650,17 @@ repo_tarballs_write() {
for tag in $(git tag); do
TARBALL_PATH="tarballs/$repo-$tag.tar.gz"
- if [ -e "$OUTDIR/$TARBALL_PATH" ]; then
- continue
- fi
- if [ ! -e "$CACHE_DIR/$TARBALL_PATH" ]; then
+ cached_run "$TARBALL_PATH" -- \
git archive --prefix "$repo-$tag/" "$tag" \
-o "$CACHE_DIR/$TARBALL_PATH"
+
+ SIGNATURE_PATH="tarballs/$repo-$tag.tar.gz.asc"
+ if git notes --ref=refs/notes/signatures/tar.gz show "$tag" \
+ 1>/dev/null 2>&1; then
+ git notes --ref=refs/notes/signatures/tar.gz show "$tag" \
+ > "$OUTDIR/$SIGNATURE_PATH"
fi
- cp "$CACHE_DIR/$TARBALL_PATH" "$OUTDIR/$TARBALL_PATH"
done
-
- # FIXME: write signatures
}
repo_commits_write() {
@@ -638,13 +673,12 @@ repo_commits_write() {
break
fi
if [ ! -e "CACHE_DIR/$COMMIT_PATH" ]; then
- print_repo_commit_page "$repo" "$commit"
print_repo_commit_page "$repo" "$commit" \
> "$CACHE_DIR/$COMMIT_PATH"
fi
cp "$CACHE_DIR/$COMMIT_PATH" "$OUTDIR/$COMMIT_PATH"
- # FIXME: dbg
+ # FIXME: WIP
return
done
done
@@ -654,10 +688,10 @@ repo_write() {
cd "$1"
repo="$(basename "$(realpath "${1%.git}")")"
description="$(cat "$1/description" 2>/dev/null ||:)"
+ CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/gistatic/$repo"
- # FIXME: hardcoded "true"
repo_tarballs_write "$repo"
- print_repo_refs "$repo" "$description" true > "$OUTDIR/refs.html"
+ print_repo_refs "$repo" "$description" > "$OUTDIR/refs.html"
repo_commits_write "$repo"
@@ -690,7 +724,7 @@ INDEX=false
TITLE="$MSG_DEFAULT_TITLE"
OUTDIR=
CLONE_URL=
-CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/gistatic"
+CACHE_DIR=
while getopts 'o:t:u:ihV' flag; do
case "$flag" in
i)