]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/morelink-plugin.mdwn
02d20329bf08f324f036ffccaef9ad6e6f780e5a
[ikiwiki.git] / doc / patchqueue / morelink-plugin.mdwn
1 Enables _Read more_ links for use in blog posts. Adds a config option for customising the anchor text.
2
3     Index: IkiWiki/Plugin/morelink.pm
4     ===================================================================
5     --- IkiWiki/Plugin/morelink.pm  (revision 0)
6     +++ IkiWiki/Plugin/morelink.pm  (revision 0)
7     @@ -0,0 +1,30 @@
8     +#!/usr/bin/perl
9     +package IkiWiki::Plugin::morelink;
10     +
11     +use warnings;
12     +use strict;
13     +use IkiWiki;
14     +
15     +my $linktext = 'Read more';
16     +
17     +sub import { #{{{
18     +    hook(type => "checkconfig", id => "more", call => \&checkconfig);
19     +    hook(type => "preprocess",  id => "more", call => \&preprocess);
20     +} # }}}
21     +
22     +sub checkconfig () { #{{{
23     +    $linktext = $config{morelink_text} || $linktext;
24     +} #}}}
25     +
26     +sub preprocess (@) { #{{{
27     +       my %args = @_;
28     +    
29     +    if ($args{page} ne $args{destpage}) {
30     +         return "\n".htmllink($args{page}, $args{destpage}, $args{page}.'#more', 0, 0, $linktext);
31     +    }
32     +       else                                {
33     +        return "<a name='more'></a>".$args{text};
34     +    }
35     +}
36     +
37     +1