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 # Can't just return the linkmap here, since the htmlscrubber
32 # scrubs out all <object> tags (with good reason!)
33 # Instead, insert a placeholder tag, which will be expanded during
36 $maps{$mapnum}=\%params;
37 return "<div class=\"linkmap$mapnum\"></div>";
43 $params{content}=~s/<div class=\"linkmap(\d+)"><\/div>/genmap($1)/eg;
45 return $params{content};
50 return "" unless exists $maps{$mapnum};
51 my %params=%{$maps{$mapnum}};
53 # Get all the items to map.
54 my %mapitems = map { $_ => urlto($_, $params{destpage}) }
55 pagespec_match_list($params{page}, $params{pages},
56 # update when a page is added or removed, or its
58 deptype => deptype("presence", "links"));
60 my $dest=$params{page}."/linkmap.png";
62 # Use ikiwiki's function to create the file, this makes sure needed
63 # subdirs are there and does some sanity checking.
64 will_render($params{page}, $dest);
65 writefile($dest, $config{destdir}, "");
67 # Run dot to create the graphic and get the map data.
70 $SIG{PIPE}=sub { $sigpipe=1 };
71 $pid=open2(*IN, *OUT, "dot -Tpng -o '$config{destdir}/$dest' -Tcmapx");
73 # open2 doesn't respect "use open ':utf8'"
74 binmode (IN, ':utf8');
75 binmode (OUT, ':utf8');
77 print OUT "digraph linkmap$mapnum {\n";
78 print OUT "concentrate=true;\n";
79 print OUT "charset=\"utf-8\";\n";
80 print OUT "ratio=compress;\nsize=\"".($params{width}+0).", ".($params{height}+0)."\";\n"
81 if defined $params{width} and defined $params{height};
82 foreach my $item (keys %mapitems) {
83 print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n";
84 foreach my $link (map { bestlink($item, $_) } @{$links{$item}}) {
85 print OUT "\"$item\" -> \"$link\";\n"
93 my $ret="<object data=\"".urlto($dest, $params{destpage}).
94 "\" type=\"image/png\" usemap=\"#linkmap$mapnum\">\n".
100 $SIG{PIPE}="DEFAULT";
101 error gettext("failed to run dot") if $sigpipe;