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