]> Sergey Matveev's repositories - swg.git/commitdiff
SWG_DO_SRC
authorSergey Matveev <stargrave@stargrave.org>
Mon, 2 Jun 2025 14:44:54 +0000 (17:44 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 2 Jun 2025 14:44:54 +0000 (17:44 +0300)
USAGE
swg

diff --git a/USAGE b/USAGE
index b0fc6b55ee793be861c62000fa82fdd6e3b0d359..117daf06ab71186c8ada39478e41d6ed92db404f 100644 (file)
--- 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 "<title>..." line in it.
diff --git a/swg b/swg
index 76f05a33775906e8f2fcd8ac895a52b41176e8dc..8d54bed5341ef7f8f564513ab3aaefa25923a243 100755 (executable)
--- 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</title>
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
-<link rel=\"alternate\" type=\"text/plain\" title=\"src\" href=\"$fn.txt\" />
+END_HTML
+;
+        print {$out} "<link rel=\"alternate\" type=\"text/plain\" title=\"src\" href=\"$fn.txt\" />\n" if $DoSrc;
+        print {$out} <<"END_HTML"
 </head>
 <body>
 <pre>
 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";