From f0c860c15471322acc3c2cfc63fa4209aa6fcfb8 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 2 Jun 2025 17:44:54 +0300 Subject: [PATCH] SWG_DO_SRC --- USAGE | 3 +++ swg | 29 ++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/USAGE b/USAGE index b0fc6b5..117daf0 100644 --- a/USAGE +++ b/USAGE @@ -25,5 +25,8 @@ be ignored by default. If $SWG_PRINT_MISSING environment variable is set, then warning will be print for links leading to non-existent pages. +If $SWG_DO_SRC=0 environment variable is set, then no links and source +pages will be generated. Pure HTML output. + How to forcefully change the title of the generated HTML page? Use sed/perl to replace "..." line in it. diff --git a/swg b/swg index 76f05a3..8d54bed 100755 --- a/swg +++ b/swg @@ -30,7 +30,8 @@ For debugging: $0 html PAGE >PAGE.html $0 gen-index CAT >CAT.html -By default SWG_DO_BACKS=1 is set. SWG_PRINT_MISSING=0. +By default SWG_DO_BACKS=1 is set. +SWG_PRINT_MISSING=0. SWG_DO_SRC=1. Do not forget about .swgignore with regular expressions. END_USAGE ; @@ -41,6 +42,8 @@ if ($#ARGV == -1) { usage } my $DoBacks = ((not exists $ENV{SWG_DO_BACKS}) or ($ENV{SWG_DO_BACKS} eq q{1})) ? 1 : 0; +my $DoSrc = ((not exists $ENV{SWG_DO_SRC}) or + ($ENV{SWG_DO_SRC} eq q{1})) ? 1 : 0; my %Mtimes; my %CatFiles; @@ -270,11 +273,15 @@ sub genHTML { <html><head> <title>$title - +END_HTML +; + print {$out} "\n" if $DoSrc; + print {$out} <<"END_HTML"
 END_HTML
+;
     }
     my $indent = q{};
     my sub procline;
@@ -508,11 +515,13 @@ if ($ARGV[0] eq q{files}) {
     foreach my $cat (keys %CatFiles) {
         make_path "$ARGV[1]/$cat";
         next if (exists $Mtimes{"${cat}index"});
-        $fn = "$ARGV[1]/${cat}index.txt";
-        open $fh, q{>:encoding(UTF-8)}, $fn or croak "$!";
-        genIndex $fh, $cat;
-        close $fh or croak "$!";
-        utime $now, $now, $fn;
+        if ($DoSrc) {
+            $fn = "$ARGV[1]/${cat}index.txt";
+            open $fh, q{>:encoding(UTF-8)}, $fn or croak "$!";
+            genIndex $fh, $cat;
+            close $fh or croak "$!";
+            utime $now, $now, $fn;
+        }
         $fn = "$ARGV[1]/${cat}index.html";
         open $fh, q{>:encoding(UTF-8)}, $fn or croak "$!";
         genHTML $fh, $cat, genIndex2Buf $cat;
@@ -531,8 +540,10 @@ if ($ARGV[0] eq q{files}) {
         } else {
             utime $mtime, $mtime, "$ARGV[1]/$pth.html";
         }
-        copy $pth, "$ARGV[1]/$pth.txt" or croak "$!";
-        utime $mtime, $mtime, "$ARGV[1]/$pth.txt";
+        if ($DoSrc) {
+            copy $pth, "$ARGV[1]/$pth.txt" or croak "$!";
+            utime $mtime, $mtime, "$ARGV[1]/$pth.txt";
+        }
     }
 } elsif ($ARGV[0] eq q{info}) {
     print "Autogenerated by swg $VERSION\n";
-- 
2.50.0