summaryrefslogtreecommitdiff
path: root/doc/patchqueue/morelink-plugin.mdwn
blob: 9724b3e3a78e00743508804b78c8ad85848db277 (plain)

Enables Read more links for use in blog posts. Adds a config option for customising the anchor text. (The [[/patchqueue/htmllink-anchors]] patch is a dependency).

Index: IkiWiki/Plugin/morelink.pm
===================================================================
--- IkiWiki/Plugin/morelink.pm  (revision 0)
+++ IkiWiki/Plugin/morelink.pm  (revision 0)
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::morelink;
+
+use warnings;
+use strict;
+use IkiWiki;
+
+my $linktext = 'Read more';
+
+sub import { #{{{
+    hook(type => "checkconfig", id => "more", call => \&checkconfig);
+    hook(type => "preprocess",  id => "more", call => \&preprocess);
+} # }}}
+
+sub checkconfig () { #{{{
+    $linktext = $config{morelink_text} || $linktext;
+} #}}}
+
+sub preprocess (@) { #{{{
+       my %args = @_;
+    
+    if ($args{page} ne $args{destpage}) {
+         return "\n".htmllink($args{page}, $args{destpage}, $args{page}.'#more', 0, 0, $linktext);
+    }
+       else                                {
+        return "<a name='more'></a>".$args{text};
+    }
+}
+
+1

--Ben