]> git.proxmox.com Git - pve-docs.git/blobdiff - asciidoc-pve.in
totp: fix copy/paste mistake
[pve-docs.git] / asciidoc-pve.in
index 92b0ca2f4192ea43a7b28c87d4c8d61916449f43..adc98c1be9afa97ef6d1afc8efbf9ede92ee95e1 100644 (file)
@@ -23,13 +23,13 @@ while (<main::DATA>) { $data_str .= $_; }
 
 my $fileinfo = decode_json($data_str);
 
-my $tmpprefix = ".asciidoc-pve-tmp_";
+my $tmpprefix = '.asciidoc-pve-tmp'.$$.'_';
 
 my $adoc_source_dir = "/usr/share/pve-doc-generator";
 
 # inside pve-docs source dir?
-if (-f "attributes.txt" && -f "pve-admin-guide.adoc") {
-    $adoc_source_dir = "."
+if (-f "asciidoc-pve.in" && -f "pve-admin-guide.adoc") {
+    $adoc_source_dir = getcwd();
 }
 
 my $prepared_files = {};
@@ -146,7 +146,10 @@ sub replace_man_xref {
     die "xref: no text for man page link '$blockid'\n" if !$text;
 
     my $section = $fileinfo->{mansection}->{manvolnum}->{$link};
-    die "link target is not a manual page" if !defined($section);
+    if (!defined($section)) {
+       warn "link '$blockid' target '$link' is not a manual page, ignoring\n";
+       return "$text";
+    }
 
 
     if ($man_target eq 'html') {
@@ -256,16 +259,14 @@ sub compile_asciidoc {
 
     my $outfile;
 
-    GetOptions ("outfile=s" => \$outfile,
-               "keep-artifacts" => \$keep_artifacts,
-               "verbose"   => \$verbose) or
-                   die("Error in command line arguments\n");
+    GetOptions (
+        "outfile=s" => \$outfile,
+        "keep-artifacts" => \$keep_artifacts,
+        "verbose"   => \$verbose
+    ) or die("Error in command line arguments\n");
 
-    my $infile = shift(@ARGV) or
-       die "no input file specified\n";
-
-    scalar(@ARGV) == 0 or
-       die "too many arguments...\n";
+    my $infile = shift(@ARGV) or die "no input file specified\n";
+    scalar(@ARGV) == 0 or die "too many arguments...\n";
 
     my $outfilemap = $fileinfo->{outfile}->{$env}->{$infile} ||
        die "no output file mapping for '$infile' ($env)";
@@ -277,14 +278,12 @@ sub compile_asciidoc {
     }
 
     if (defined($outfile)) {
-       die "wrong output file name '$outfile != $outfilemap' ($env)"
-           if $outfile ne $outfilemap;
+       die "wrong output file name '$outfile != $outfilemap' ($env)" if $outfile ne $outfilemap;
     } else {
        $outfile = $outfilemap;
     }
 
-    defined($fileinfo->{titles}->{$env}) ||
-       die "unknown environment '$env'";
+    defined($fileinfo->{titles}->{$env}) || die "unknown environment '$env'";
 
     my $title = $fileinfo->{titles}->{$env}->{$infile} or
        die "unable to get title for '$infile'$env\n";
@@ -300,7 +299,12 @@ sub compile_asciidoc {
 
     $leveloffset = - $doctype;
 
-    my $date = `date`;
+    my $date;
+    if (defined($ENV{SOURCE_DATE_EPOCH})) {
+       $date = `date -d "\@$ENV{SOURCE_DATE_EPOCH}"`;
+    } else {
+       $date = `date`;
+    }
     chomp $date;
 
     my $attributes = {
@@ -308,6 +312,7 @@ sub compile_asciidoc {
        leveloffset => $leveloffset,
        revnumber => $release,
        revdate => $date,
+       'footer-style' => 'revdate',
     };
 
     my $mansection = $fileinfo->{mansection}->{$env}->{$infile};
@@ -318,7 +323,7 @@ sub compile_asciidoc {
        $attributes->{manvolnum} = $mansection;
     } elsif ($env eq 'default') {
        die "$infile: wrong doctype\n" if $doctype != 0;
-       $attributes->{toc} = undef;
+       $attributes->{toc2} = undef;
     }
 
     if (!defined($outfile)) {
@@ -341,7 +346,13 @@ sub compile_asciidoc {
        # section like footnotes, so we cannot use a2x.
        # We use xmlto instead.
 
-       my $cmd = ['asciidoc', '-dmanpage', '-bdocbook', '-a', 'docinfo1'];
+       my $cmd = [
+           'asciidoc',
+           '-dmanpage',
+           '-b', "$adoc_source_dir/asciidoc/pve-docbook",
+           '-f', "$adoc_source_dir/asciidoc/asciidoc-pve.conf",
+           '-a', 'docinfo1',
+       ];
 
        foreach my $key (keys %$attributes) {
            my $value = $attributes->{$key};
@@ -366,8 +377,7 @@ sub compile_asciidoc {
 
        debug("run " . join(' ', @$cmd));
 
-       system(@$cmd) == 0 or
-           die "aciidoc error";
+       system(@$cmd) == 0 or die "aciidoc error";
 
        $cmd = ['xmlto', 'man', $tmpxmlfile];
 
@@ -375,27 +385,21 @@ sub compile_asciidoc {
 
        debug("run " . join(' ', @$cmd));
 
-       system(@$cmd) == 0 or
-           die "xmlto error";
+       system(@$cmd) == 0 or die "xmlto error";
 
     } else {
 
        $attributes->{icons} = undef;
        $attributes->{'data-uri'} = undef;
 
-       my $cmd = ['asciidoc'];
+       my $cmd = [ 'asciidoc', '-f', "$adoc_source_dir/asciidoc/asciidoc-pve.conf" ];
 
        if (($env eq 'wiki') ||
            (($env eq 'manvolnum') && ($man_target eq 'wiki'))) {
 
-           push @$cmd, '-s';
-
-           if (-f "./asciidoc/mediawiki.conf") {
-               my $cwd = getcwd();
-               push @$cmd, '-b', "$cwd/asciidoc/mediawiki";
-           } else {
-               push @$cmd, '-b', "mediawiki";
-           }
+           push @$cmd, '-b', "$adoc_source_dir/asciidoc/mediawiki";
+       } else {
+           push @$cmd, '-b', "$adoc_source_dir/asciidoc/pve-html";
        }
 
        foreach my $key (keys %$attributes) {
@@ -417,8 +421,7 @@ sub compile_asciidoc {
 
        debug("run " . join(' ', @$cmd));
 
-       system(@$cmd) == 0 or
-           die "aciidoc error";
+       system(@$cmd) == 0 or die "aciidoc error";
     }
 }
 
@@ -457,7 +460,7 @@ sub scan_extjs_file {
     debug("scan-extjs $filename");
 
     while(defined(my $line = <$fh>)) {
-       if ($line =~ m/\s+onlineHelp:\s*[\'\"](.*?)[\'\"]/) {
+       if ($line =~ m/\s+onlineHelp:\s*[\'\"]([^{}\[\]\'\"]+)[\'\"]/) {
            my $blockid = $1;
            my $link = $fileinfo->{blockid_target}->{default}->{$blockid};
            die "undefined blockid '$blockid' ($filename, line $.)\n"
@@ -571,14 +574,14 @@ if ($clicmd eq 'compile-wiki') {
     my $data_str =  to_json($res_data, { pretty => 1,  canonical => 1 });
     chomp $data_str;
 
-    print "var pveOnlineHelpInfo = ${data_str};\n";
+    print "const pveOnlineHelpInfo = ${data_str};\n";
 
 } elsif ($clicmd eq 'chapter-table') {
-    
+
     print '[width="100%",options="header"]' . "\n";
     print "|====\n";
     print "|Title|Link\n";
-    
+
     my $filelist = $fileinfo->{outfile}->{default};
     foreach my $sourcefile (sort keys %$filelist) {
        my $target = $filelist->{$sourcefile};
@@ -587,16 +590,16 @@ if ($clicmd eq 'compile-wiki') {
            die "not title for '$sourcefile'";
        print "|$title|link:$target\[\]\n";
     }
-    
+
     print "|====\n";
 
 } elsif ($clicmd =~ m/^man([158])page-table$/) {
-    
+
     my $section = $1;
     print '[width="100%",cols="5*d",options="header"]' . "\n";
     print "|====\n";
     print "|Name 3+|Title|Link\n";
-    
+
     my $filelist = $fileinfo->{outfile}->{manvolnum};
     foreach my $manpage (sort keys %$filelist) {
        next if $section ne $fileinfo->{mansection}->{manvolnum}->{$manpage};
@@ -610,8 +613,8 @@ if ($clicmd eq 'compile-wiki') {
        
        my $target = $filelist->{$manpage};
        print "|$mantitle 3+|$title|link:$target.html\[$target\]\n";
-    }  
-    
+    }
+
     print "|====\n";
 
 } else {