\t$0 backs PAGE
\t$0 cats [PREFIX]
\t$0 htmls DIR
-\t$0 dot | dot -Tpng >png
+\t$0 dot | dot -Tpng >relations.png
+\t$0 info >out.info
By default ZK_DO_BACKS=1 is set.
Do not forget about .zkignore with regular expressions.
print $out "do-backs\r\n";
}
+sub genIndex2Buf {
+ my $p = shift;
+ my $buf = "";
+ open(my $fh, ">:encoding(UTF-8)", \$buf) or die "$!";
+ genIndex $fh, $p;
+ close $fh;
+ return $buf;
+}
+
sub htmlescape {
$_ = shift;
s/&/\&/g;
return $backsWereGenerated;
}
-sub genIndex2Buf {
- my $p = shift;
- my $buf = "";
- open(my $fh, ">:encoding(UTF-8)", \$buf) or die "$!";
- genIndex $fh, $p;
+sub nodename {
+ $_ = $_[0];
+ tr/./-/;
+ return $_;
+}
+
+sub genInfo {
+ my $page = shift;
+ my %links;
+ if ($page =~ /\/$/) {
+ foreach ((@{$CatFiles{$page}}, @{$CatDirs{$page}})) {
+ $links{$_} = 1;
+ }
+ } elsif (exists $Links{noindex $page}) {
+ foreach (@{$Links{noindex $page}}) {
+ $links{$_} = 1;
+ }
+ }
+ open(my $fh, "<:encoding(UTF-8)", $page) or die "$!";
+ while (<$fh>) {
+ chop;
+ if (/\r$/) {
+ chop;
+ /^\s*(.*)$/;
+ if ($1 =~ /^do-backs/) {
+ next;
+ }
+ if ($1 =~ /^#/) {
+ next;
+ }
+ }
+ s/\[([^]]+)\]/my $n = nodename $1; (exists $links{$1}) ? ("*note ${n}::") : $1/ge;
+ print "$_\n";
+ }
close $fh;
- return $buf;
+ my @backs = sort keys %{$Backs{noindex $page}};
+ if ($#backs != -1) {
+ print "\n* Menu:\nBacklinks:\n";
+ foreach (@backs) {
+ print "* " . (nodename $_) . ": " . (nodename $_) . ".\n";
+ }
+ print "\n";
+ }
+}
+
+sub genInfoIndex {
+ my $page = shift;
+ my $pth;
+ print "* Menu:\n\n";
+ foreach (sort @{$CatFiles{$page}}) {
+ print "* " . (nodename $_) . ": " . (nodename $_) . ".\n";
+ }
+ print "\n";
+ my @links = sort @{$CatDirs{$page}};
+ if ($#links != -1) {
+ print "\n* Menu:\nSubcategories:\n";
+ foreach (@links) {
+ print "* " . (nodename $_) . ": " . (nodename $_) . ".\n";
+ }
+ print "\n";
+ }
+ @links = sort keys %{$Backs{noindex $page}};
+ if ($#links != -1) {
+ print "\n* Menu:\nBacklinks:\n";
+ foreach (@links) {
+ print "* " . (nodename $_) . ": " . (nodename $_) . ".\n";
+ }
+ print "\n";
+ }
}
if ($ARGV[0] eq "dump") {
copy $pth, "$ARGV[1]/$pth.txt" or die "$!";
utime $s[9], $s[9], "$ARGV[1]/$pth.txt";
}
+} elsif ($ARGV[0] eq "info") {
+ print "Autogenerated by zk\n";
+ my $sep = "\n\1f\n";
+ print "${sep}File: self, Node: Top, Up: (dir)\n\n";
+ if (exists $Mtimes{"index"}) {
+ genInfo "index";
+ delete $Mtimes{"index"};
+ delete $CatFiles{"/"};
+ delete $CatDirs{"/"};
+ } else {
+ genInfoIndex "/";
+ delete $CatFiles{"/"};
+ delete $CatDirs{"/"};
+ }
+ sub up {
+ my $p = dirname noindex $_[0];
+ if (($p eq ".") or ($p eq "/")) {
+ return "Top";
+ }
+ return (nodename $p) . "/";
+ }
+ foreach my $cat (keys %CatFiles) {
+ next if (exists $Mtimes{"${cat}index"});
+ print "${sep}File: self, Node: " . (nodename $cat) .
+ ", Up: " . (up $cat) . "\n\n";
+ genInfoIndex $cat;
+ }
+ foreach my $page (keys %Mtimes) {
+ print "${sep}File: self, Node: " . (nodename noindex $page) .
+ ", Up: " . (up $page) . "\n\n";
+ genInfo $page;
+ }
+ print "${sep}File: self, Node: index, Up: Top\n\n";
+ print "\0\b[index\0\b]\n* Menu:\n";
+ foreach my $cat (keys %CatFiles) {
+ print "* " . (nodename $cat) . ": " .
+ (nodename $cat) . ". (line 0)\n";
+ }
+ foreach my $page (keys %Mtimes) {
+ print "* " . (nodename noindex $page) . ": " .
+ (nodename noindex $page) . ". (line 0)\n";
+ }
+ print "${sep}Local Variables:\ncoding: utf-8\nEnd:\n";
} elsif ($ARGV[0] eq "dot") {
print "digraph d {\n";
print "rankdir=LR\n";