5
0
mirror of git://git.proxmox.com/git/pve-docs.git synced 2025-03-20 22:50:06 +03:00

pve-docs-mediawiki-import.in: include text version inside pvehide tag

So that wiki search returns useful content.
This commit is contained in:
Dietmar Maurer 2016-10-17 10:35:55 +02:00
parent 208f75bc96
commit 3f4666b456
2 changed files with 48 additions and 11 deletions

2
debian/control vendored
View File

@ -23,7 +23,7 @@ Description: Proxmox VE Documentation
Package: pve-docs-mediawiki
Architecture: all
Section: doc
Depends: ${misc:Depends}, pve-docs
Depends: ${misc:Depends}, pve-docs, libhtml-parser-perl
Suggests: apache2
Description: Proxmox VE Documentation - mediawiki plugin
This package contains tools to view Proxmox VE Documentation with mediakiki.

View File

@ -7,6 +7,7 @@ use Data::Dumper;
use IO::File;
use File::Basename;
use MediaWiki::API;
use HTML::Parser;
use JSON;
@ -35,25 +36,61 @@ $mw->login({ lgname => $username, lgpassword => $passwd })
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
sub update_page {
my ($pagename, $include, $category) = @_;
my ($pagename, $filename, $category) = @_;
print "update mediawiki page: $pagename\n";
my $ref = $mw->get_page( { title => $pagename } );
my $page = $ref->{'*'} || '';
if ($page !~ m/^\{\{#pvedocs:.*\}\}\s*$/m) {
$page = "{{#pvedocs:$include}}\n$page";
} else {
$page =~ s/^\{\{#pvedocs:.*\}\}\s*$/\{\{#pvedocs:$include\}\}\n/m;
my $pve_content = "<!-- Do not edit - this is autogenerated content -->\n";
$pve_content .= "{{#pvedocs:$filename}}\n";
$pve_content .= "[[Category:$category]]\n" if $category;
my $starttag = '<!--PVE_IMPORT_START_MARKER-->';
my $endtag = '<!--PVE_IMPORT_END_MARKER-->';
$pve_content .= "<pvehide>\n";
my $parser_opts = {
api_version => 3,
text_h => [ sub { $pve_content .= shift }, "dtext" ],
};
my $parser = HTML::Parser->new(%$parser_opts);
my $fh = IO::File->new("/usr/share/pve-docs/$filename", "r") or
die "unable to open file '$filename' - $!\n";
while (defined(my $line = <$fh>)) {
$parser->parse($line);
}
$pve_content .= "</pvehide>\n";
if ($category) {
my $catstr = "Category:$category";
$pve_content =~ s/\s+$//gm;
if ($page !~ m/^\[\[$catstr\]\]\s*$/m) {
$page .= "\n[[$catstr]]\n";
}
chomp $pve_content;
if ($page =~ m/^(.*)$starttag\n.*\n$endtag(.*)$/s) {
my ($top_content, $bottom_content) = ($1, $2);
chomp $top_content;
chomp $bottom_content;
$page = $top_content;
$page .= "$starttag\n";
$page .= $pve_content;
$page .= "\n$endtag\n";
$page .= $bottom_content;
} elsif ($page =~ m/(.*)\{\{#pvedocs:.*?\}\}(.*)$/) {
# old style
my ($top_content, $bottom_content) = ($1, $2);
chomp $top_content;
chomp $bottom_content;
$page = $top_content;
$page .= "$starttag\n";
$page .= $pve_content;
$page .= "\n$endtag\n";
$page .= $bottom_content;
} else {
$page = "$starttag\n$pve_content\n$endtag\n$page";
}
my $timestamp = $ref->{timestamp};