5
0
mirror of git://git.proxmox.com/git/pve-docs.git synced 2025-01-06 13:17:48 +03:00

asciidoc-pve.in: implement new command print-links-json

prints/stores information about defined blockids with titles/subtitles.
We can use this for the GUI.
This commit is contained in:
Dietmar Maurer 2016-10-12 11:45:06 +02:00
parent ae43d78c78
commit dd284d2569

View File

@ -422,6 +422,51 @@ if ($clicmd eq 'compile-wiki') {
die $err if $err;
} elsif ($clicmd eq 'print-links-json') {
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 = {};
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);
}
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;
}
} else {
die "unknown command '$clicmd'\n";