use File::Path;
use File::Basename;
use IO::File;
+use Cwd;
use JSON;
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 = {};
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') {
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;
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'";
$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 = {
leveloffset => $leveloffset,
revnumber => $release,
revdate => $date,
+ 'footer-style' => 'revdate',
};
my $mansection = $fileinfo->{mansection}->{$env}->{$infile};
# 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};
$attributes->{icons} = undef;
$attributes->{'data-uri'} = undef;
- my $cmd = ['asciidoc'];
+ my $cmd = ['asciidoc',
+ '-f', "$adoc_source_dir/asciidoc/asciidoc-pve.conf",
+ ];
- push @$cmd, '-s' if ($env eq 'wiki') ||
- (($env eq 'manvolnum') && ($man_target eq 'wiki'));
+ 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};
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";