summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/tag.pm36
-rw-r--r--IkiWiki/Render.pm33
2 files changed, 56 insertions, 13 deletions
diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm
index cdcfaf536..af4bff1bc 100644
--- a/IkiWiki/Plugin/tag.pm
+++ b/IkiWiki/Plugin/tag.pm
@@ -6,8 +6,6 @@ use warnings;
use strict;
use IkiWiki 3.00;
-my %tags;
-
sub import {
hook(type => "getopt", id => "tag", call => \&getopt);
hook(type => "getsetup", id => "tag", call => \&getsetup);
@@ -36,6 +34,13 @@ sub getsetup () {
safe => 1,
rebuild => 1,
},
+ tagged_is_strict => {
+ type => "boolean",
+ default => 0,
+ description => "if 1, tagged() doesn't match normal WikiLinks to tag pages",
+ safe => 1,
+ rebuild => 1,
+ },
}
sub tagpage ($) {
@@ -71,9 +76,8 @@ sub preprocess_tag (@) {
foreach my $tag (keys %params) {
$tag=linkpage($tag);
- $tags{$page}{$tag}=1;
# hidden WikiLink
- add_link($page, tagpage($tag));
+ add_link($page, tagpage($tag), 'tag');
}
return "";
@@ -87,15 +91,13 @@ sub preprocess_taglink (@) {
return join(" ", map {
if (/(.*)\|(.*)/) {
my $tag=linkpage($2);
- $tags{$params{page}}{$tag}=1;
- add_link($params{page}, tagpage($tag));
+ add_link($params{page}, tagpage($tag), 'tag');
return taglink($params{page}, $params{destpage}, $tag,
linktext => pagetitle($1));
}
else {
my $tag=linkpage($_);
- $tags{$params{page}}{$tag}=1;
- add_link($params{page}, tagpage($tag));
+ add_link($params{page}, tagpage($tag), 'tag');
return taglink($params{page}, $params{destpage}, $tag);
}
}
@@ -110,17 +112,19 @@ sub pagetemplate (@) {
my $destpage=$params{destpage};
my $template=$params{template};
+ my $tags = $typedlinks{$page}{tag};
+
$template->param(tags => [
map {
link => taglink($page, $destpage, $_, rel => "tag")
- }, sort keys %{$tags{$page}}
- ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
+ }, sort keys %$tags
+ ]) if defined $tags && %$tags && $template->query(name => "tags");
if ($template->query(name => "categories")) {
# It's an rss/atom template. Add any categories.
- if (exists $tags{$page} && %{$tags{$page}}) {
+ if (defined $tags && %$tags) {
$template->param(categories => [map { category => $_ },
- sort keys %{$tags{$page}}]);
+ sort keys %$tags]);
}
}
}
@@ -130,7 +134,13 @@ package IkiWiki::PageSpec;
sub match_tagged ($$;@) {
my $page = shift;
my $glob = shift;
- return match_link($page, IkiWiki::Plugin::tag::tagpage($glob));
+
+ if ($IkiWiki::config{tagged_is_strict}) {
+ return match_link($page, IkiWiki::Plugin::tag::tagpage($glob), linktype => 'tag');
+ }
+ else {
+ return match_link($page, IkiWiki::Plugin::tag::tagpage($glob));
+ }
}
1
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index abafb0887..5810fc974 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -167,6 +167,7 @@ sub scan ($) {
else {
$links{$page}=[];
}
+ delete $typedlinks{$page};
run_hooks(scan => sub {
shift->(
@@ -398,6 +399,7 @@ sub find_del_files ($) {
push @del, $pagesources{$page};
}
$links{$page}=[];
+ delete $typedlinks{$page};
$renderedfiles{$page}=[];
$pagemtime{$page}=0;
}
@@ -499,6 +501,29 @@ sub remove_unrendered () {
}
}
+sub link_types_changed ($$) {
+ # each is of the form { type => { link => 1 } }
+ my $new = shift;
+ my $old = shift;
+
+ return 0 if !defined $new && !defined $old;
+ return 1 if !defined $new || !defined $old;
+
+ while (my ($type, $links) = each %$new) {
+ foreach my $link (keys %$links) {
+ return 1 unless exists $old{$type}{$link};
+ }
+ }
+
+ while (my ($type, $links) = each %$old) {
+ foreach my $link (keys %$links) {
+ return 1 unless exists $new{$type}{$link};
+ }
+ }
+
+ return 0;
+}
+
sub calculate_changed_links ($$$) {
my ($changed, $del, $oldlink_targets)=@_;
@@ -525,6 +550,14 @@ sub calculate_changed_links ($$$) {
}
$linkchangers{lc($page)}=1;
}
+
+ # we currently assume that changing the type of a link doesn't
+ # change backlinks
+ if (!exists $linkchangers{lc($page)}) {
+ if (link_types_changed($typedlinks{$page}, $oldlinktypes{$page})) {
+ $linkchangers{lc($page)}=1;
+ }
+ }
}
return \%backlinkchanged, \%linkchangers;