]> git.proxmox.com Git - pve-docs.git/blobdiff - scan-adoc-refs
generate wiki output file mappings automatically
[pve-docs.git] / scan-adoc-refs
index cf6385e592e170101b3c3c00c786d83c90f49dc2..03dc51cf59f668da803c738d3fbb09b8f58b3ea4 100755 (executable)
@@ -14,7 +14,52 @@ my $environments = {
     pvelogo => 0, # ignore
 };
 
-my $fileinfo = {};
+my $fileinfo = {
+    outfile => {
+       default => {
+           "pve-admin-guide.adoc" => "pve-admin-guide.html",
+           "datacenter.cfg.adoc" => "datacenter.cfg.5.html",
+           "ha-manager.adoc" => "chapter-ha-manager.html",
+           "pct.adoc" => "chapter-pct.html",
+           "pve-bibliography.adoc" => "chapter-pve-bibliography.html",
+           "pve-firewall.adoc" => "chapter-pve-firewall.html",
+           "pve-installation.adoc" => "chapter-pve-installation.html",
+           "pvecm.adoc" => "chapter-pvecm.html",
+           "pvesm.adoc" => "chapter-pvesm.html",
+           "pveum.adoc" => "chapter-pveum.html",
+           "qm.adoc" => "chapter-qm.html",
+           "sysadmin.adoc" => "chapter-sysadmin.html",
+           "vzdump.adoc" => "chapter-vzdump.html",
+           "pmxcfs.adoc" => "chapter-pmxcfs.html",
+           "pve-faq.adoc" => "chapter-pve-faq.html",
+       },
+       manvolnum => {
+           "ha-manager.adoc" => "ha-manager.1",
+           "pct.adoc" => "pct.1",
+           "pveam.adoc" => "pveam.1",
+           "pveceph.adoc" => "pveceph.1",
+           "pvecm.adoc" => "pvecm.1",
+           "pveperf.adoc" => "pveperf.1",
+           "pvesm.adoc" => "pvesm.1",
+           "pvesubscription.adoc" => "pvesubscription.1",
+           "pveum.adoc" => "pveum.1",
+           "qm.adoc" => "qm.1",
+           "qmrestore.adoc" => "qmrestore.1",
+           "vzdump.adoc" => "vzdump.1",
+           "datacenter.cfg.adoc" => "datacenter.cfg.5",
+           "pct.conf.adoc" => "pct.conf.5",
+           "qm.conf.adoc" => "qm.conf.5",
+           "pmxcfs.adoc" => "pmxcfs.8",
+           "pvedaemon.adoc" => "pvedaemon.8",
+           "pve-firewall.adoc" => "pve-firewall.8",
+           "pve-ha-crm.adoc" => "pve-ha-crm.8",
+           "pve-ha-lrm.adoc" => "pve-ha-lrm.8",
+           "pveproxy.adoc" => "pveproxy.8",
+           "pvestatd.adoc" => "pvestatd.8",
+           "spiceproxy.adoc" => "spiceproxy.8",
+       },
+    },
+};
 
 my $start_env = [];
 foreach my $e (keys %$environments) {
@@ -241,8 +286,9 @@ sub resolve_link_target {
     while ($repeat) {
        $repeat = 0;
        foreach my $fn (keys %$include_hash) {
-           next if $fn eq 'pve-admin-guide.adoc';
            if ($include_hash->{$fn}->{$filename}) {
+               next if ($fn eq 'pve-admin-guide.adoc') &&
+                   $fileinfo->{outfile}->{$env}->{$filename};
                $filename = $fn;
                $repeat = 1;
                last;
@@ -253,6 +299,24 @@ sub resolve_link_target {
     return $filename;
 }
 
+
+# try to generate output file mapping
+foreach my $e (@$start_env) {
+    my $toplevel_hash = $fileinfo->{toplevel}->{$e};
+    foreach my $fn (sort keys %$toplevel_hash) {
+       my $mansection = $fileinfo->{mansection}->{manvolnum}->{$fn};
+       if ($e eq 'wiki') {
+           my $realfn = $fn;
+           $realfn =~ s/\.adoc$//;
+           if (defined($mansection) && ($mansection == 5)) {
+               $realfn .= ".$mansection";
+           }
+           my $realfn = "$realfn-plain.html";
+           $fileinfo->{outfile}->{$e}->{$fn} = $realfn;
+       }
+    }
+}
+
 # now resolve blockids
 foreach my $e (@$start_env) {
     my $blockid_hash = $fileinfo->{blockid}->{$e};
@@ -263,17 +327,19 @@ foreach my $e (@$start_env) {
            $title =~ s/\s/_/g;
            die "found not title for '$fn' in env '$e'" if !$title;
            $fileinfo->{blockid_target}->{$e}->{$blockid} = "link:/wiki/$title#$blockid";
+
+           # we do not produce wiki pages for all content
+           #my $realfn = $fileinfo->{outfile}->{$e}->{$fn};
+           #warn "no output file mapping for '$fn' ($e)\n" if !$realfn;
+
        } elsif ($e eq 'default') {
-           my $realfn = $fn;
-           $realfn =~ s/\.adoc//;
-           if (($realfn eq 'datacenter.cfg') || ($realfn eq 'qm.conf') || ($realfn eq 'pct.conf')) {
-               $realfn .= ".5";
-           } else {
-               $realfn = "chapter-$realfn";
-           }
-           $realfn .= ".html";
+           my $realfn = $fileinfo->{outfile}->{$e}->{$fn} ||
+               die "no output file mapping for '$fn'\n";
            $fileinfo->{blockid_target}->{$e}->{$blockid} = "link:/pve-docs/$realfn#$blockid";
-       } else {
+       } elsif ($e eq 'manvolnum') {
+           # we do not produce manpages for all content
+           # my $realfn = $fileinfo->{outfile}->{$e}->{$fn} ||
+           # warn "no output file mapping for '$fn'\n";
            $fileinfo->{blockid_target}->{$e}->{$blockid} = $fn;
        }
     }