]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/datearchives-plugin.mdwn
* Changed calling convention for httmllink slightly. The first three
[ikiwiki.git] / doc / patchqueue / datearchives-plugin.mdwn
1 I'll be using IkiWiki primarily as a blog, so I want a way to view entries by date. A URL of the form `/date/YYYY/MM/DD.html` (or `/date/YYYY/MM/DD/` when using the `use_dirs` patch) should show posts from that period. ATM, I have this:
2
3 <pre>
4 Index: IkiWiki/Plugin/datearchives.pm
5 ===================================================================
6 --- IkiWiki/Plugin/datearchives.pm      (revision 0)
7 +++ IkiWiki/Plugin/datearchives.pm      (revision 0)
8 @@ -0,0 +1,31 @@
9 +#!/usr/bin/perl
10 +
11 +package IkiWiki::Plugin::datearchives;
12 +
13 +use warnings;
14 +use strict;
15 +use IkiWiki;
16 +
17 +sub import { #{{{
18 +    hook(type => "pagetemplate", id => "datearchives", call => \&pagetemplate, scan => 1);
19 +} # }}}
20 +
21 +sub pagetemplate (@) { #{{{
22 +    my %args = @_;
23 +    my $dt;
24 +    eval {
25 +        use DateTime;
26 +        $dt = DateTime->from_epoch(epoch => $IkiWiki::pagectime{ $args{page} });
27 +    };
28 +    return if $@;
29 +    my $base = $config{datearchives_base} || 'date';
30 +    my $link = $base.'/'.$dt->strftime('%Y/%m/%d');
31 +    push @{$links{$args{page}}}, $link;
32 +    my $template = $args{template};
33 +       if ($template->query(name => "ctime")) {
34 +        $template->param(ctime => htmllink( $args{page}, $args{destpage}, $link, 0, 0,
35 +                                            $template->param('ctime')));
36 +       }
37 +} # }}}
38 +
39 +1
40 </pre>
41
42 This works (although accessing `%IkiWiki::pagectime` is not too clever), but it would be far more useful if the date pages were automatically created and populated with the relevant posts. A [[Pagespec]] works perfectly for displaying the relevant content, but we're still left with the issue of actually creating the page. What's the Right Way to do this? We could create them in the RCS working copy and check them in, or create them directly in the output directory... (I'd also like to create an option for the tags plugin to auto-create its targets in the same way). Any opinions? :-)