commit eaff998d0c2b01b7f1d77b62028814840f773ef4
parent 03f822f31f9296d26f9022937810381e11b23903
Author: masayoshi <masayoshi@example.com>
Date: Mon, 23 Feb 2026 11:50:59 +0900
Upload
Diffstat:
| A | update-stagit.pl | | | 97 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 97 insertions(+), 0 deletions(-)
diff --git a/update-stagit.pl b/update-stagit.pl
@@ -0,0 +1,97 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+# -----------------------------------------------------------------------------
+# Name: update-stagit.pl
+# Description: Universal static site generator for stagit with automated
+# navigation link insertion for OpenBSD.
+# Version: 1.0.7 (2026-01-01)
+# Author: masayoshi
+# License: ISC License
+# -----------------------------------------------------------------------------
+# Copyright (c) 2026 masayoshi
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+# -----------------------------------------------------------------------------
+
+# --- Configuration ---
+my $base_wwwDir = "/var/www/stagit";
+my $stagit_bin = "/usr/local/bin/stagit";
+my $index_bin = "/usr/local/bin/stagit-index";
+
+# --- 1. Identify Repository from Arguments ---
+my $repo_path = $ARGV[0];
+if ( !$repo_path ) {
+ print "Error: No repository path provided.\n";
+ exit 1;
+}
+
+# Resolve repository name (e.g., /var/www/stagit/diary.git -> diary)
+my $repo_git_name = ( $repo_path =~ m|/([^/]+)/?$| )[0] || $repo_path;
+my $repo_bare_name = $repo_git_name;
+$repo_bare_name =~ s/\.git$//;
+
+my $target_dir = "$base_wwwDir/$repo_bare_name";
+
+print "--- update-stagit v1.0.7 ---\n";
+print "Processing repository: $repo_bare_name\n";
+
+# --- 2. Update Repository Pages ---
+if ( !-d $target_dir ) {
+ print "Initialising new directory: $target_dir\n";
+ mkdir $target_dir, 0755 or die "Cannot create directory: $!";
+}
+
+if ( chdir $target_dir ) {
+ print "Generating HTML via stagit...\n";
+ system( $stagit_bin, $repo_path );
+
+ # Insert Navigation Link to all generated HTML files
+ my @html_files = glob( "*.html" );
+ foreach my $file ( @html_files ) {
+ if ( open my $fh, '<', $file ) {
+ local $/;
+ my $content = <$fh>;
+ close $fh;
+
+ # Check if link already exists to prevent duplicate insertion
+ if ( $content !~ m|stagit-index-link| ) {
+ my $link_html =
+ qq|<hr/><div class="stagit-index-link" style="margin: 10px 0; font-family: sans-serif;">|
+ . qq|<b><a href="/stagit/index.html">← Back to Portal (All Repositories)</a></b></div>|;
+
+ # Insert link after the first horizontal rule
+ if ( $content =~ s|<hr\s*/?>|$link_html| ) {
+ if ( open my $out, '>', $file ) {
+ print $out $content;
+ close $out;
+ }
+ }
+ }
+ }
+ }
+
+ # Ensure log.html is the default index for the repository
+ if ( -e "log.html" ) {
+ unlink( "index.html" );
+ symlink( "log.html", "index.html" );
+ }
+ system( "chmod 644 *.html" );
+}
+
+# --- 3. Update Global Portal (stagit-index) ---
+if ( chdir $base_wwwDir ) {
+ my @all_repos = glob( "*.git" );
+ if ( @all_repos ) {
+ print "Updating global portal index...\n";
+ system( "$index_bin @all_repos > index.html.tmp" );
+ rename( "index.html.tmp", "index.html" );
+ chmod 0644, "index.html";
+ }
+}
+
+print "Success: $repo_bare_name is updated and linked to portal.\n";
+print "----------------------------\n";