]> git.proxmox.com Git - pve-docs.git/blobdiff - scan-adoc-refs
generate default output file mappings automatically
[pve-docs.git] / scan-adoc-refs
index 216b244b74f5a6a99da73723e9cb1a946ecc0716..b0bc340f4daa18b43c213bac5875b3cd54710bd3 100755 (executable)
@@ -241,8 +241,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 +254,45 @@ 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";
+           }
+           $realfn = "$realfn-plain.html";
+           $fileinfo->{outfile}->{$e}->{$fn} = $realfn;
+       } elsif ($e eq 'manvolnum') {
+           my $realfn = $fn;
+           $realfn =~ s/\.adoc$//;
+           die "toplevel file '$fn' is not marked as manual page!" if !$mansection;
+           $realfn .= ".$mansection";
+           $fileinfo->{outfile}->{$e}->{$fn} = $realfn;
+       } elsif ($e eq 'default') {
+           my $realfn = $fn;
+           $realfn =~ s/\.adoc$//;                 
+           if (defined($mansection) && ($mansection == 5)) {
+               $realfn .= ".$mansection";
+               $realfn = "$realfn.html";
+           } else {
+               if (($fn ne 'pve-admin-guide.adoc') &&
+                   $fileinfo->{doctype}->{$e}->{$fn} == 0) {
+                   $realfn = "chapter-$realfn.html";       
+               } else {
+                   $realfn = "$realfn.html";
+               }
+           }
+           $fileinfo->{outfile}->{$e}->{$fn} = $realfn;
+       }
+    }
+}
+
 # now resolve blockids
 foreach my $e (@$start_env) {
     my $blockid_hash = $fileinfo->{blockid}->{$e};
@@ -263,11 +303,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 = "chapter-$fn";
-           $realfn =~ s/\.adoc/.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;
        }
     }