X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/e3c6b9bb9d6cef040f9c3f8a86337cf340966806..e3ccf393c6081e413e1da0eae46ac937a032a13b:/IkiWiki/Plugin/linkmap.pm diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index 5b87277ac..0137476ac 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -3,18 +3,27 @@ package IkiWiki::Plugin::linkmap; use warnings; use strict; -use IkiWiki 2.00; +use IkiWiki 3.00; use IPC::Open2; -sub import { #{{{ +sub import { + hook(type => "getsetup", id => "linkmap", call => \&getsetup); hook(type => "preprocess", id => "linkmap", call => \&preprocess); hook(type => "format", id => "linkmap", call => \&format); -} # }}} +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => undef, + }, +} my $mapnum=0; my %maps; -sub preprocess (@) { #{{{ +sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; @@ -30,34 +39,33 @@ sub preprocess (@) { #{{{ $mapnum++; $maps{$mapnum}=\%params; return "
"; -} # }}} +} -sub format (@) { #{{{ +sub format (@) { my %params=@_; $params{content}=~s/
<\/div>/genmap($1)/eg; return $params{content}; -} # }}} +} -sub genmap ($) { #{{{ +sub genmap ($) { my $mapnum=shift; return "" unless exists $maps{$mapnum}; my %params=%{$maps{$mapnum}}; # Get all the items to map. my %mapitems = (); - foreach my $item (keys %links) { - if (pagespec_match($item, $params{pages}, location => $params{page})) { - $mapitems{$item}=urlto($item, $params{destpage}); - } + foreach my $item (pagespec_match_list([keys %links], + $params{pages}, location => $params{page})) { + $mapitems{$item}=urlto($item, $params{destpage}); } - my $dest=$params{destpage}."/linkmap.png"; + my $dest=$params{page}."/linkmap.png"; # Use ikiwiki's function to create the file, this makes sure needed # subdirs are there and does some sanity checking. - will_render($params{destpage}, $dest); + will_render($params{page}, $dest); writefile($dest, $config{destdir}, ""); # Run dot to create the graphic and get the map data. @@ -86,7 +94,7 @@ sub genmap ($) { #{{{ close OUT; local $/=undef; - my $ret="\n". . ""; @@ -94,11 +102,9 @@ sub genmap ($) { #{{{ waitpid $pid, 0; $SIG{PIPE}="DEFAULT"; - if ($sigpipe) { - return "[[linkmap ".gettext("failed to run dot")."]]"; - } + error gettext("failed to run dot") if $sigpipe; return $ret; -} #}}} +} 1