2 package IkiWiki::Plugin::linkmap;
10 hook(type => "getsetup", id => "linkmap", call => \&getsetup);
11 hook(type => "preprocess", id => "linkmap", call => \&preprocess);
12 hook(type => "format", id => "linkmap", call => \&format);
29 $params{pages}="*" unless defined $params{pages};
31 # Needs to update whenever a relevant page is added, or removed, or
33 add_depends($params{page}, $params{pages}, presence => 1, links => 1);
35 # Can't just return the linkmap here, since the htmlscrubber
36 # scrubs out all <object> tags (with good reason!)
37 # Instead, insert a placeholder tag, which will be expanded during
40 $maps{$mapnum}=\%params;
41 return "<div class=\"linkmap$mapnum\"></div>";
47 $params{content}=~s/<div class=\"linkmap(\d+)"><\/div>/genmap($1)/eg;
49 return $params{content};
54 return "" unless exists $maps{$mapnum};
55 my %params=%{$maps{$mapnum}};
57 # Get all the items to map.
59 foreach my $item (keys %links) {
60 if (pagespec_match($item, $params{pages}, location => $params{page})) {
61 $mapitems{$item}=urlto($item, $params{destpage});
65 my $dest=$params{page}."/linkmap.png";
67 # Use ikiwiki's function to create the file, this makes sure needed
68 # subdirs are there and does some sanity checking.
69 will_render($params{page}, $dest);
70 writefile($dest, $config{destdir}, "");
72 # Run dot to create the graphic and get the map data.
75 $SIG{PIPE}=sub { $sigpipe=1 };
76 $pid=open2(*IN, *OUT, "dot -Tpng -o '$config{destdir}/$dest' -Tcmapx");
78 # open2 doesn't respect "use open ':utf8'"
79 binmode (IN, ':utf8');
80 binmode (OUT, ':utf8');
82 print OUT "digraph linkmap$mapnum {\n";
83 print OUT "concentrate=true;\n";
84 print OUT "charset=\"utf-8\";\n";
85 print OUT "ratio=compress;\nsize=\"".($params{width}+0).", ".($params{height}+0)."\";\n"
86 if defined $params{width} and defined $params{height};
87 foreach my $item (keys %mapitems) {
88 print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n";
89 foreach my $link (map { bestlink($item, $_) } @{$links{$item}}) {
90 print OUT "\"$item\" -> \"$link\";\n"
98 my $ret="<object data=\"".urlto($dest, $params{destpage}).
99 "\" type=\"image/png\" usemap=\"#linkmap$mapnum\">\n".
105 $SIG{PIPE}="DEFAULT";
106 error gettext("failed to run dot") if $sigpipe;