gitpages

A collection of scripts to securely webhost and publish git repositories.
git clone https://scm.kuandu.systems/git-raw/gitpages.git
Log | Files | Refs | README | LICENSE

commit 421197b776866b084ee3b1bd5ea39be870b959e6
parent f72e4dda131a7698ac36ebe8d083647431d553a5
Author: Fred Großkopf <fred@kuandu.systems>
Date:   Thu, 23 Apr 2026 00:31:15 +0200

Update repo html <title> rewriting

With title format "prefix - reponame - description",
and config setting REPO_TITLE_DESCRIPTION,
replaces entire " - description" part

Diffstat:
MREADME.md | 3++-
Mgitpages.sh | 13+++++++------
Mtest-gitpages.sh | 14++++++--------
3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md @@ -69,6 +69,7 @@ Example: SITE_NAME=mycompany INDEX_TITLE=New Title INDEX_DESCRIPTION=New Description +REPO_TITLE_DESCRIPTION= | $SITE_NAME ``` If gitpages.conf exists or is passed with -c, gitpages.sh rewrites: @@ -83,5 +84,5 @@ If gitpages.conf exists or is passed with -c, gitpages.sh rewrites: - repository pages title tags: ```html -<title>Log - myrepo - mycompany</title> +<title>Log - myrepo | mycompany</title> ``` diff --git a/gitpages.sh b/gitpages.sh @@ -89,11 +89,11 @@ generate_repo_html() { process_repo_titles() { repo="$1" repo_name="$2" html_repo_dir="$3" [ -d "$html_repo_dir" ] || return 0 - [ -n "${SITE_NAME:-}" ] || return 0 + [ -n "${REPO_TITLE_DESC:-}" ] || return 0 - esc_site=$(sed_escape "$SITE_NAME") + esc_description=$(sed_escape "$REPO_TITLE_DESC") find "$html_repo_dir" -name "*.html" -type f -exec sed -i \ - "s|<title>\([^<]* - $repo_name - \)[^<]*|<title>\1$esc_site|g" {} + + "s| - $repo_name - [^<]*| - $repo_name$esc_description|g" {} + } generate_index() { @@ -143,13 +143,14 @@ load_config() { cfg="$1" [ -r "$cfg" ] || return 0 - for key in SITE_NAME INDEX_TITLE INDEX_DESCRIPTION; do + for key in SITE_NAME INDEX_TITLE INDEX_DESCRIPTION REPO_TITLE_DESCRIPTION; do val=$(awk -F= -v k="$key" '$1 == k {print $2; exit}' "$cfg") || continue [ -n "$val" ] || continue case "$key" in SITE_NAME) SITE_NAME="$val" ;; INDEX_TITLE) INDEX_TITLE="$val" ;; INDEX_DESCRIPTION) INDEX_DESC="$val" ;; + REPO_TITLE_DESCRIPTION) REPO_TITLE_DESC="$val" ;; esac done } @@ -178,7 +179,7 @@ main() { check_args "$@" SRC="$1" DST_DIR="$2" ASSETS_DIR="${3:-}" - SITE_NAME="" INDEX_TITLE="" INDEX_DESC="" + SITE_NAME="" INDEX_TITLE="" INDEX_DESC="" REPO_TITLE_DESC="" # Validate prerequisites check_html_writable && check_stagit && check_assets @@ -190,7 +191,7 @@ main() { else SRC_DIR="$SRC" SINGLE_REPO="" - has_git_repos "$SRC_DIR" || error "$SRC is neither git repo nor dir with *.git repos" + has_git_repos "$SRC_DIR" || error "$SRC is neither git repo nor dir with *.git Repos" fi # Load config diff --git a/test-gitpages.sh b/test-gitpages.sh @@ -149,7 +149,6 @@ test_full_sync() { test_stale_cleanup() { printf '=== Test 6: Stale cleanup ===\n' mkdir -p "$HTML_DST/stale-repo" - echo "stale" > "$HTML_DST/stale-repo/index.html" mkdir -p "$RAW_SRC/repo1.git" (cd "$RAW_SRC/repo1.git" && git init --bare . > /dev/null 2>&1) @@ -250,18 +249,17 @@ test_repo_titles_without_rewriting() { } test_repo_titles_rewriting() { - printf '=== Test 10b: Titles end with " - mycompany" (with rewriting) ===\n' + printf '=== Test 10b: Titles end with "X mycompany" (with rewriting) ===\n' mkdir -p "$RAW_SRC/demo.git" (cd "$RAW_SRC/demo.git" && git init --bare . > /dev/null 2>&1) - config_file="$TEST_BASE/gitweb.conf" - printf 'SITE_NAME=mycompany\n' > "$config_file" + config_file="$TEST_BASE/gitpages.conf" + printf 'REPO_TITLE_DESCRIPTION=X mycompany\n' > "$config_file" html_dst_with_c="$HTML_DST/with-mycompany" mkdir -p "$html_dst_with_c" - #"$SCRIPT_NAME" -c "$config_file" "$RAW_SRC/demo.git" "$html_dst_with_c" > /dev/null 2>&1 || error "$SCRIPT_NAME failed with -c" "$SCRIPT_NAME" -c "$config_file" "$RAW_SRC/demo.git" "$html_dst_with_c" || error "$SCRIPT_NAME failed with -c" myrepo_html_with_c="$html_dst_with_c/demo" @@ -271,14 +269,14 @@ test_repo_titles_rewriting() { find "$myrepo_html_with_c" -name "*.html" -type f | while IFS= read -r f; do title=$(extract_title "$f") - if printf '%s\n' "$title" | grep -q ' - mycompany$'; then + if printf '%s\n' "$title" | grep -q 'X mycompany$'; then : # good else - error "title in $f (with -c) does not end with ' - mycompany': '$title'" + error "title in $f (with -c) does not end with 'X mycompany': '$title'" fi done - success "With -c, titles end with ' - mycompany'" + success "With -c, titles end with 'X mycompany'" } test_index_rewriting() {