From 764051fdf6f50c75a88359a2a4b4edad6ff9b4d9 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 9 May 2025 22:56:02 +0300 Subject: [PATCH] Ability to include pages --- zk | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/zk b/zk index c634b03..ac1e4ce 100755 --- 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 \[(.*)\] $/) { + 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 "\n\n
";
     my $doLinksForced = 0;
     my $doBacksForced = 0;
-    open(my $fh, "<", $page) or die "$!";
-    while (<$fh>) {
+    my sub procline;
+    sub procline {
+        $_ = $_[0];
         chop;
         if (/
$/) {
             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 "
\n"; if ($doLinksForced or ($doLinks and $#lnks != -1)) { -- 2.48.1