]> git.proxmox.com Git - pve-docs.git/blobdiff - asciidoc-pve.in
make dinstall: skip mediawiki deb for now
[pve-docs.git] / asciidoc-pve.in
index 582267db3bbc9c8afb8b4b950add1312ac2b9ee5..d1a754d5a0f5034d15e4f95a4287d4065b12c1c8 100644 (file)
@@ -6,6 +6,7 @@ use Getopt::Long;
 use File::Path;
 use File::Basename;
 use IO::File;
+use Cwd;
 
 use JSON;
 
@@ -22,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 = {};
@@ -37,6 +38,21 @@ my $man_target = 'man';
 my $env_stack = [];
 my $env_skip = 0;
 
+my $online_help_links = {
+    'pve_service_daemons' => {
+       link => '/pve-docs/index.html#_service_daemons',
+       title => 'Service Daemons',
+    },
+    'pve_documentation_index' => {
+       link => '/pve-docs/index.html',
+       title => 'Proxmox VE Documentation Index',
+    },
+    'pve_admin_guide' => {
+       link => '/pve-docs/pve-admin-guide.html',
+       title => 'Proxmox VE Administration Guide',
+    },
+};
+
 sub debug {
     my $msg = shift;
 
@@ -130,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') {
@@ -218,6 +237,12 @@ sub prepare_adoc_file {
            next;
        }
 
+       if ($line =~ m/xref:\S+?\[[^\]]*$/) {
+           die "possible xref spanning multiple lines in '$filename':\n(line $.): $line\n";
+       }
+       if ($line =~ m/<<((?!\>\>).)*$/) {
+           die "possible xref spanning multiple lines in '$filename':\n(line $.): $line\n";
+       }
        # fix xrefs
        $line =~ s/xref:([^\s\[\]]+)\[([^\]]*)\]/replace_xref(${target_env},$1,$2)/ge;
 
@@ -245,6 +270,22 @@ sub compile_asciidoc {
     scalar(@ARGV) == 0 or
        die "too many arguments...\n";
 
+    my $outfilemap = $fileinfo->{outfile}->{$env}->{$infile} ||
+       die "no output file mapping for '$infile' ($env)";
+
+    if ($man_target eq 'html') {
+       $outfilemap .= '.html';
+    } elsif ($man_target eq 'wiki') {
+       $outfilemap .= '-plain.html';
+    }
+
+    if (defined($outfile)) {
+       die "wrong output file name '$outfile != $outfilemap' ($env)"
+           if $outfile ne $outfilemap;
+    } else {
+       $outfile = $outfilemap;
+    }
+
     defined($fileinfo->{titles}->{$env}) ||
        die "unknown environment '$env'";
 
@@ -262,12 +303,20 @@ 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 = {
        $env => undef,
        leveloffset => $leveloffset,
+       revnumber => $release,
+       revdate => $date,
+       'footer-style' => 'revdate',
     };
 
     my $mansection = $fileinfo->{mansection}->{$env}->{$infile};
@@ -301,7 +350,9 @@ 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', '-bdocbook',
+                  '-f', "$adoc_source_dir/asciidoc/asciidoc-pve.conf",
+                  '-a', 'docinfo1'];
 
        foreach my $key (keys %$attributes) {
            my $value = $attributes->{$key};
@@ -342,12 +393,18 @@ sub compile_asciidoc {
 
        $attributes->{icons} = undef;
        $attributes->{'data-uri'} = undef;
-       $attributes->{revnumber} = $release;
 
-       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 ($env eq 'wiki') ||
-           (($env eq 'manvolnum') && ($man_target eq 'wiki'));
+           push @$cmd, '-b', "$adoc_source_dir/asciidoc/mediawiki";
+       } else {
+           push @$cmd, '-b', "$adoc_source_dir/asciidoc/pve-html";
+       }
 
        foreach my $key (keys %$attributes) {
            my $value = $attributes->{$key};
@@ -373,6 +430,52 @@ sub compile_asciidoc {
     }
 }
 
+sub get_links {
+
+    my $data = {};
+
+    foreach my $blockid (sort keys %{$fileinfo->{blockid_target}->{default}}) {
+       my $link = $fileinfo->{blockid_target}->{default}->{$blockid};
+       my $reftitle = $fileinfo->{reftitle}->{default}->{$blockid};
+       my $reftext = $fileinfo->{reftext}->{default}->{$blockid};
+       die "internal error" if $link !~ m/^link:/;
+       $link =~ s/^link://;
+
+       my $file = $fileinfo->{blockid}->{default}->{$blockid};
+       die "internal error - no filename" if ! defined($file);
+       my $title =  $fileinfo->{titles}->{default}->{$file} ||
+           die "internal error - no title";
+
+       $data->{$blockid}->{title} = $title;
+       $data->{$blockid}->{link} = $link;
+       my $subtitle = $reftitle || $reftext;
+       $data->{$blockid}->{subtitle} = $subtitle
+           if $subtitle && ($title ne $subtitle);
+    }
+
+    return $data;
+}
+
+sub scan_extjs_file {
+    my ($filename, $res_data) = @_;
+
+    my $fh = IO::File->new($filename, "r") ||
+       die "unable to open '$filename' - $!\n";
+
+    debug("scan-extjs $filename");
+
+    while(defined(my $line = <$fh>)) {
+       if ($line =~ m/\s+onlineHelp:\s*[\'\"](.*?)[\'\"]/) {
+           my $blockid = $1;
+           my $link = $fileinfo->{blockid_target}->{default}->{$blockid};
+           die "undefined blockid '$blockid' ($filename, line $.)\n"
+               if !(defined($link) || defined($online_help_links->{$blockid}));
+
+           $res_data->{$blockid} = 1;
+       }
+    }
+}
+
 if ($clicmd eq 'compile-wiki') {
 
     eval { compile_asciidoc('wiki'); };
@@ -422,15 +525,108 @@ if ($clicmd eq 'compile-wiki') {
 
     die $err if $err;
 
-} else {
+} elsif ($clicmd eq 'print-links') {
 
-    die "unknown command '$clicmd'\n";
+    my $outfile;
 
-}
+    GetOptions("outfile=s" => \$outfile,
+              "verbose"   => \$verbose) or
+                  die("Error in command line arguments\n");
+
+    scalar(@ARGV) == 0 or
+       die "too many arguments...\n";
+
+    my $data = get_links();
+
+    my $res = to_json($data, { pretty => 1,  canonical => 1 } );
+
+    if (defined($outfile)) {
+       my $outfh = IO::File->new("$outfile", "w") or
+           die "unable to open temporary file '$outfile'\n";
+
+       print $outfh $res;
+
+    } else {
 
+       print $res;
+    }
+
+} elsif ($clicmd eq 'scan-extjs') {
+
+    GetOptions("verbose" => \$verbose) or
+       die("Error in command line arguments\n");
+
+    my $link_hash = {};
+    my $scanned_files = {};
+    while (my $filename = shift) {
+       die "got strange file name '$filename'\n"
+           if $filename !~ m/\.js$/;
+       next if $scanned_files->{$filename};
 
+       scan_extjs_file($filename, $link_hash);
+       $scanned_files->{$filename} = 1;
+    }
+
+    my $data = get_links();
 
+    my $res_data = {};
+
+    foreach my $blockid (keys %$link_hash) {
+       $res_data->{$blockid} = $data->{$blockid} || $online_help_links->{$blockid} ||
+           die "internal error - no data for '$blockid'";
+    }
 
+    my $data_str =  to_json($res_data, { pretty => 1,  canonical => 1 });
+    chomp $data_str;
+
+    print "var 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};
+       next if $target eq 'pve-admin-guide.html';
+       my $title = $fileinfo->{titles}->{default}->{$sourcefile} ||
+           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};
+       my $mantitle = $fileinfo->{titles}->{manvolnum}->{$manpage} ||
+           die "not manual title for '$manpage'";
+       my $title = $fileinfo->{titles}->{default}->{$manpage} ||
+           die "not title for '$manpage'";
+
+       # hack - remove command name prefix from titles
+       $title =~ s/^[a-z]+\s*-\s*//;
+       
+       my $target = $filelist->{$manpage};
+       print "|$mantitle 3+|$title|link:$target.html\[$target\]\n";
+    }  
+    
+    print "|====\n";
+
+} else {
+
+    die "unknown command '$clicmd'\n";
+
+}
 
 
 exit 0;