po: added postscan hook, to make pages depend on the pages linking to them
authorintrigeri <intrigeri@boum.org>
Wed, 31 Dec 2008 21:27:12 +0000 (22:27 +0100)
committerintrigeri <intrigeri@boum.org>
Thu, 1 Jan 2009 00:08:10 +0000 (01:08 +0100)
... so that nicepagetitle hook's effects, such as translation status displayed
in links, are updated when the linked page changes.

The replacement of 'my %backlinks' with 'our %backlinks' in Render.pm made this
work: previously, every postscan hook was called with an almost empty
%backlinks, which defeated all my attempts to implement this feature.

This feature hits performance a bit. Its cost was quite small in my real-world
use-cases (a few percents bigger refresh time), but could be bigger in worst
cases. Time will tell.

NB: this hack could also be used by my meta branch. It may even be a ikiwiki
optional feature.

Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
IkiWiki/Render.pm
doc/plugins/po.mdwn

index 33bc2b0577153b20815fb4dd1b8e9519b7972be5..c529828d69bf85775bf3141c44891e8872abea71 100644 (file)
@@ -35,6 +35,7 @@ sub import { #{{{
        hook(type => "filter", id => "po", call => \&filter);
        hook(type => "htmlize", id => "po", call => \&htmlize);
        hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
+       hook(type => "postscan", id => "po", call => \&postscan);
        hook(type => "rename", id => "po", call => \&renamepages);
        hook(type => "delete", id => "po", call => \&mydelete);
        hook(type => "change", id => "po", call => \&change);
@@ -340,6 +341,16 @@ sub pagetemplate (@) { #{{{
        }
 } # }}}
 
+sub postscan (@) {
+       my %params = @_;
+       my $page = $params{page};
+
+       # backlinks involve back-dependencies, so that nicepagetitle effects,
+       # such as translation status displayed in links, are updated
+       use IkiWiki::Render;
+       map add_depends($page, $_), keys %{$IkiWiki::backlinks{$page}};
+}
+
 # Add the renamed page translations to the list of to-be-renamed pages.
 # Save information about master page rename, so that:
 # - our delete hook can ignore the translations not renamed already
index adae9f0d5898dee39190a29328fa7e221c82dcdc..0ce972ac7883856992878df1d4d247b02feacd71 100644 (file)
@@ -7,7 +7,7 @@ use strict;
 use IkiWiki;
 use Encode;
 
-my %backlinks;
+our %backlinks=();
 my $backlinks_calculated=0;
 
 sub calculate_backlinks () {
index 4ce8ad7d9c293ad367e1fa1e8428816157cb64a3..7d8da987e117c538a9f5120d8db6459242cc6bb3 100644 (file)
@@ -511,10 +511,6 @@ intrigeri's `meta` branch, the generated links' text is based on the
 page titles set with the [[meta|plugins/meta]] plugin. This has to be
 merged upstream, though.
 
-### Backlinks
-
-They are not updated when the source page changes (e.g. meta title).
-
 Page formats
 ------------