2 # Ikiwiki "blocks" relationship plugin.
3 package IkiWiki::Plugin::blocks;
10 hook(type => "getsetup", id => "blocks", call => \&getsetup);
11 hook(type => "checkconfig", id => "skeleton", call => \&checkconfig);
22 example => "blocks/blockedby",
23 description => "comma separated list of defined relationship pairs, the forward and backward name separated by a slash",
31 if (defined $config{blocks_names}) {
32 $blocksnames = $config{blocks_names};
34 $blocksnames = "blocks/blockedby";
37 while ( $blocksnames =~ /([^ ]+)/g )
39 if ( $1 =~ m@([a-zA-Z0-9]+)(/([a-zA-Z0-9]+))?@ )
45 shortcut => 1, # gets interpreted by listdirectives; see doc/bugs/cannot_preview_shortcuts.mdwn / ikiwiki commit 354d22e2
49 call => sub { preprocess_blocks($from, 1, @_); }
59 call => sub { preprocess_blocks($from, 0, @_); }
63 my $backward_match; my $backward_name;
64 my $forward_match; my $forward_name;
66 $backward_match = sub ($$;@) {
69 return IkiWiki::PageSpec::match_backlink($page, $glob, linktype => $from, @_);
72 $backward_name = "IkiWiki::PageSpec::match_$from";
76 $forward_match = sub ($$;@) {
79 return IkiWiki::PageSpec::match_link($page, $glob, linktype => $from, @_);
82 $forward_name = "IkiWiki::PageSpec::match_$to";
90 *$forward_name = $forward_match;
92 *$backward_name = $backward_match;
95 error gettext("Malformed option in blocks_names");
100 sub preprocess_blocks ($$@) {
101 # with flip=0, the directive occurring on page A pointing at page B
102 # means that A $relation B, with flip=1, it means B $relation A
103 my $relation = shift;
110 my $page = $params{page};
111 delete $params{page};
112 delete $params{destpage};
113 delete $params{preview};
115 foreach my $blocks (keys %params) {
116 $blocks=linkpage($blocks);
120 add_link($page, $blocks, $relation);
122 add_link($blocks, $page, $relation);