mirror of
https://git.proxmox.com/git/pve-docs
synced 2025-04-30 04:44:51 +00:00
pve-docs-mediawiki-import.in: include text version inside pvehide tag
So that wiki search returns useful content.
This commit is contained in:
parent
208f75bc96
commit
3f4666b456
2
debian/control
vendored
2
debian/control
vendored
@ -23,7 +23,7 @@ Description: Proxmox VE Documentation
|
|||||||
Package: pve-docs-mediawiki
|
Package: pve-docs-mediawiki
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Section: doc
|
Section: doc
|
||||||
Depends: ${misc:Depends}, pve-docs
|
Depends: ${misc:Depends}, pve-docs, libhtml-parser-perl
|
||||||
Suggests: apache2
|
Suggests: apache2
|
||||||
Description: Proxmox VE Documentation - mediawiki plugin
|
Description: Proxmox VE Documentation - mediawiki plugin
|
||||||
This package contains tools to view Proxmox VE Documentation with mediakiki.
|
This package contains tools to view Proxmox VE Documentation with mediakiki.
|
||||||
|
@ -7,6 +7,7 @@ use Data::Dumper;
|
|||||||
use IO::File;
|
use IO::File;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use MediaWiki::API;
|
use MediaWiki::API;
|
||||||
|
use HTML::Parser;
|
||||||
|
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
@ -35,25 +36,61 @@ $mw->login({ lgname => $username, lgpassword => $passwd })
|
|||||||
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
|
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
|
||||||
|
|
||||||
sub update_page {
|
sub update_page {
|
||||||
my ($pagename, $include, $category) = @_;
|
my ($pagename, $filename, $category) = @_;
|
||||||
|
|
||||||
print "update mediawiki page: $pagename\n";
|
print "update mediawiki page: $pagename\n";
|
||||||
|
|
||||||
my $ref = $mw->get_page( { title => $pagename } );
|
my $ref = $mw->get_page( { title => $pagename } );
|
||||||
my $page = $ref->{'*'} || '';
|
my $page = $ref->{'*'} || '';
|
||||||
|
|
||||||
if ($page !~ m/^\{\{#pvedocs:.*\}\}\s*$/m) {
|
my $pve_content = "<!-- Do not edit - this is autogenerated content -->\n";
|
||||||
$page = "{{#pvedocs:$include}}\n$page";
|
|
||||||
} else {
|
$pve_content .= "{{#pvedocs:$filename}}\n";
|
||||||
$page =~ s/^\{\{#pvedocs:.*\}\}\s*$/\{\{#pvedocs:$include\}\}\n/m;
|
$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) {
|
$pve_content =~ s/\s+$//gm;
|
||||||
my $catstr = "Category:$category";
|
|
||||||
|
|
||||||
if ($page !~ m/^\[\[$catstr\]\]\s*$/m) {
|
chomp $pve_content;
|
||||||
$page .= "\n[[$catstr]]\n";
|
|
||||||
}
|
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};
|
my $timestamp = $ref->{timestamp};
|
||||||
|
Loading…
Reference in New Issue
Block a user