]> Sergey Matveev's repositories - zk.git/commitdiff
text/plain alternate
authorSergey Matveev <stargrave@stargrave.org>
Wed, 7 May 2025 19:09:50 +0000 (22:09 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 8 May 2025 07:01:39 +0000 (10:01 +0300)
zk

diff --git a/zk b/zk
index a08f2ee9437be74f2a3fffe227986bbb0628a0b9..3742ee34f5959b5379c3606d3910299ac8c7f513 100755 (executable)
--- a/zk
+++ b/zk
@@ -179,14 +179,14 @@ for my $pth (keys %mtimes) {
     }
 }
 
-sub startBody {
+sub startHead {
     my $out = shift;
     my $title = shift;
     print $out "<!DOCTYPE html>
 <html><head>
 <title>$title</title>
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
-</head><body>";
+";
 }
 
 sub htmlescape {
@@ -198,6 +198,7 @@ sub htmlescape {
 }
 
 use File::Spec;
+use File::Basename;
 
 sub genHTML {
     my $out = shift;
@@ -215,8 +216,13 @@ sub genHTML {
             push @rels, $rel;
         }
     }
-    startBody $out, $page;
-    print $out "<pre>\n";
+    startHead $out, $page;
+    {
+        my $fn = basename $page;
+        print $out "<link rel=\"alternate\" type=\"text/plain\" title=\"plain\"
+    href=\"$fn.txt\" />\n";
+    }
+    print $out "</head><body><pre>";
     open(my $fh, "<", $page) or die "$!";
     while (<$fh>) {
         chop;
@@ -277,8 +283,8 @@ sub genHTML {
 sub genIndex {
     my $out = shift;
     my $page = shift;
-    startBody $out, "$page/";
-    print $out "<table border=1>\n";
+    startHead $out, "$page/";
+    print $out "</head><body><table border=1>\n";
     my @lnks = sort @{$cats{$page}};
     foreach my $l (@lnks) {
         next if $l =~ /\/$/;
@@ -343,6 +349,12 @@ if ($ARGV[0] eq "dump") {
         close $fh;
         @s = stat($pth) or die "$!";
         utime $s[9], $s[9], "$ARGV[1]/$pth.html";
+        open(my $in, "<", $pth) or die "$!";
+        open(my $out, ">", "$ARGV[1]/$pth.txt") or die "$!";
+        while (<$in>) { print $out $_ };
+        close $out;
+        close $in;
+        utime $s[9], $s[9], "$ARGV[1]/$pth.txt";
     }
 } elsif ($ARGV[0] eq "dot") {
     print "digraph d {\n";