2 package IkiWiki::Plugin::linkmap;
10 hook(type => "getsetup", id => "linkmap", call => \&getsetup);
11 hook(type => "preprocess", id => "linkmap", call => \&preprocess);
27 $params{pages}="*" unless defined $params{pages};
30 my $connected=IkiWiki::yesno($params{connected});
32 # Get all the items to map.
33 my %mapitems = map { $_ => urlto($_, $params{destpage}) }
34 pagespec_match_list($params{page}, $params{pages},
35 # update when a page is added or removed, or its
37 deptype => deptype("presence", "links"));
39 my $dest=$params{page}."/linkmap.png";
41 # Use ikiwiki's function to create the file, this makes sure needed
42 # subdirs are there and does some sanity checking.
43 will_render($params{page}, $dest);
44 writefile($dest, $config{destdir}, "");
46 # Run dot to create the graphic and get the map data.
49 $SIG{PIPE}=sub { $sigpipe=1 };
50 $pid=open2(*IN, *OUT, "dot -Tpng -o '$config{destdir}/$dest' -Tcmapx");
52 # open2 doesn't respect "use open ':utf8'"
53 binmode (IN, ':utf8');
54 binmode (OUT, ':utf8');
56 print OUT "digraph linkmap$mapnum {\n";
57 print OUT "concentrate=true;\n";
58 print OUT "charset=\"utf-8\";\n";
59 print OUT "ratio=compress;\nsize=\"".($params{width}+0).", ".($params{height}+0)."\";\n"
60 if defined $params{width} and defined $params{height};
64 if (! $shown{$item}) {
65 print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n";
69 foreach my $item (keys %mapitems) {
70 $show->($item) unless $connected;
71 foreach my $link (map { bestlink($item, $_) } @{$links{$item}}) {
72 next unless length $link and $mapitems{$link};
73 foreach my $endpoint ($item, $link) {
76 print OUT "\"$item\" -> \"$link\";\n";
80 close OUT || error gettext("failed to run dot");
83 my $ret="<img src=\"".urlto($dest, $params{destpage}).
84 "\" alt=\"".gettext("linkmap").
85 "\" usemap=\"#linkmap$mapnum\" />\n".
87 close IN || error gettext("failed to run dot");
91 error gettext("failed to run dot");
94 error gettext("failed to run dot") if $sigpipe;