]> Sergey Matveev's repositories - zk.git/commitdiff
Keep autogenerated indices
authorSergey Matveev <stargrave@stargrave.org>
Sun, 11 May 2025 07:44:46 +0000 (10:44 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 11 May 2025 07:44:46 +0000 (10:44 +0300)
zk

diff --git a/zk b/zk
index d9f772fadf1f84d719363cc6f74687f572f6a315..8c4c471404bc176c1a7c3b51f7f1cac35aabc4cb 100755 (executable)
--- a/zk
+++ b/zk
@@ -189,12 +189,10 @@ sub genHTML {
     my $page = shift;
     my $buf = shift;
     my $doBacks = $DoBacks;
-    my $doAlt = 1;
     my @links = ();
     if ($page =~ /\/$/) {
         @links = (@{$CatFiles{$page}}, @{$CatDirs{$page}});
         $doBacks = 0;
-        $doAlt = 0;
     } elsif (exists $Links{noindex $page}) {
         @links = @{$Links{noindex $page}};
     }
@@ -219,15 +217,15 @@ sub genHTML {
     makerels;
     {
         my $title = noindex $page;
-        my $fn = basename $page;
+        my $fn = ($page =~ /\/$/) ? "index" : basename $page;
         print $out "<!DOCTYPE html>
 <html><head>
 <title>$title</title>
-<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
-        if ($doAlt) {
-            print $out "\n<link rel=\"alternate\" type=\"text/plain\" title=\"src\" href=\"$fn.txt\" />";
-        }
-        print $out "\n</head>\n<body>\n<pre>";
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
+<link rel=\"alternate\" type=\"text/plain\" title=\"src\" href=\"$fn.txt\" />
+</head>
+<body>
+<pre>";
     }
     my $indent = "";
     my sub procline;
@@ -358,20 +356,27 @@ if ($ARGV[0] eq "dump") {
     my $now = time;
     use File::Path qw(make_path);
     use File::Copy;
+    my $fh;
+    my $fn;
     foreach my $cat (keys %CatFiles) {
         make_path "$ARGV[1]/$cat";
         next if (exists $Mtimes{"${cat}index"});
-        my $fn = "$ARGV[1]/${cat}index.html";
-        open(my $fh, ">:encoding(UTF-8)", $fn) or die "$!";
+        $fn = "$ARGV[1]/${cat}index.txt";
+        open($fh, ">:encoding(UTF-8)", $fn) or die "$!";
+        genIndex $fh, $cat;
+        close $fh;
+        $fn = "$ARGV[1]/${cat}index.html";
+        open($fh, ">:encoding(UTF-8)", $fn) or die "$!";
         genHTML $fh, $cat, genIndex2Buf $cat;
         close $fh;
         utime $now, $now, $fn;
     }
+    my @s;
     foreach my $pth (keys %Mtimes) {
-        open(my $fh, ">:encoding(UTF-8)", "$ARGV[1]/$pth.html") or die "$!";
+        open($fh, ">:encoding(UTF-8)", "$ARGV[1]/$pth.html") or die "$!";
         my $backsWereGenerated = genHTML $fh, $pth;
         close $fh;
-        my @s = stat($pth) or die "$!";
+        @s = stat($pth) or die "$!";
         if ($backsWereGenerated) {
             utime $now, $now, "$ARGV[1]/$pth.html";
         } else {