]> Sergey Matveev's repositories - zk.git/commitdiff
Ability to include pages
authorSergey Matveev <stargrave@stargrave.org>
Fri, 9 May 2025 19:56:02 +0000 (22:56 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 9 May 2025 19:56:02 +0000 (22:56 +0300)
zk

diff --git a/zk b/zk
index c634b03436daf61175b7af7ad6b77b1c332b7aa3..ac1e4cefab43c9ac4328ea8a3e1dfa00bc426037 100755 (executable)
--- a/zk
+++ b/zk
@@ -198,26 +198,34 @@ my %links;
 my %backs;
 for my $pth (keys %mtimes) {
     my %found;
-    open(my $fh, "<", $pth) or die "$!";
-    while (<$fh>) {
-        foreach my $w (split /\s+/) {
+    my sub procline;
+    sub procline {
+        if (/^include \[(.*)\]\r$/) {
+            open(my $fh, "<", $1) or die "$!";
+            while (<$fh>) { procline $_ }
+            close $fh;
+            return;
+        }
+        foreach my $w (split /\s+/, $_[0]) {
             next unless $w =~ /\[([^]]+)\]/;
             $w = $1;
             if ($w =~ /\/$/) {
                 my $w = substr $w, 0, -1;
                 if (not exists $cats{$w}) {
                     print "missing $w\n" if exists $ENV{ZK_PRINT_MISSING};
-                    next;
+                    return;
                 }
             } else {
                 if (not exists $mtimes{$w}) {
                     print "missing $w\n" if exists $ENV{ZK_PRINT_MISSING};
-                    next;
+                    return;
                 }
             }
             $found{$w} = 1;
         }
     }
+    open(my $fh, "<", $pth) or die "$!";
+    while (<$fh>) { procline $_ }
     close $fh;
     my @ws = sort keys %found;
     next if $#ws == -1;
@@ -279,8 +287,9 @@ sub genHTML {
     print $out "</head>\n<body>\n<pre>";
     my $doLinksForced = 0;
     my $doBacksForced = 0;
-    open(my $fh, "<", $page) or die "$!";
-    while (<$fh>) {
+    my sub procline;
+    sub procline {
+        $_ = $_[0];
         chop;
         if (/\r$/) {
             chop;
@@ -302,15 +311,19 @@ sub genHTML {
                 }
             } elsif ($cols[0] eq "do-links") {
                 $doLinksForced = 1;
-                next;
+                return;
             } elsif ($cols[0] eq "do-backs") {
                 $doBacksForced = 1;
-                next;
+                return;
             } elsif ($cols[0] eq "raw") {
                 $_ = join " ", @cols[1..$#cols];
             } elsif ($cols[0] eq "#") {
-                # this is commented string
-                next;
+                return;
+            } elsif ($cols[0] eq "include") {
+                open(my $fh, "<", substr $cols[1], 1, -1) or die "$!";
+                while (<$fh>) { procline $_ }
+                close $fh;
+                return;
             } else {
                 die "unknown $cols[0] command: $page\n";
             }
@@ -324,6 +337,8 @@ sub genHTML {
         }
         print $out "$_\n";
     }
+    open(my $fh, "<", $page) or die "$!";
+    while (<$fh>) { procline $_ }
     close $fh;
     print $out "</pre>\n";
     if ($doLinksForced or ($doLinks and $#lnks != -1)) {