massive patchqueue reorg
[ikiwiki] / doc / todo / datearchives-plugin.mdwn
1 I'll be using IkiWiki primarily as a blog, so I want a way to view entries
2 by date. A URL of the form `/date/YYYY/MM/DD.html` (or `/date/YYYY/MM/DD/`
3 when using the `use_dirs` patch) should show posts from that period. ATM, I
4 have this:
5
6 <pre>
7 Index: IkiWiki/Plugin/datearchives.pm
8 ===================================================================
9 --- IkiWiki/Plugin/datearchives.pm      (revision 0)
10 +++ IkiWiki/Plugin/datearchives.pm      (revision 0)
11 @@ -0,0 +1,31 @@
12 +#!/usr/bin/perl
13 +
14 +package IkiWiki::Plugin::datearchives;
15 +
16 +use warnings;
17 +use strict;
18 +use IkiWiki;
19 +
20 +sub import { #{{{
21 +    hook(type => "pagetemplate", id => "datearchives", call => \&pagetemplate, scan => 1);
22 +} # }}}
23 +
24 +sub pagetemplate (@) { #{{{
25 +    my %args = @_;
26 +    my $dt;
27 +    eval {
28 +        use DateTime;
29 +        $dt = DateTime->from_epoch(epoch => $IkiWiki::pagectime{ $args{page} });
30 +    };
31 +    return if $@;
32 +    my $base = $config{datearchives_base} || 'date';
33 +    my $link = $base.'/'.$dt->strftime('%Y/%m/%d');
34 +    push @{$links{$args{page}}}, $link;
35 +    my $template = $args{template};
36 +       if ($template->query(name => "ctime")) {
37 +        $template->param(ctime => htmllink( $args{page}, $args{destpage}, $link, 0, 0,
38 +                                            $template->param('ctime')));
39 +       }
40 +} # }}}
41 +
42 +1
43 </pre>
44
45 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? :-)
46
47 > Ok, first, I don't understand what your plugin does. Maybe I need to get
48 > some sleep, but a better explanation might help. :-) It seems to make
49 > links from pages to the archive pages? But I don't understand why you
50 > want such links .. wouldn't a sidebar with links to the available archive
51 > pages work better? Or something else, depending on personal preference.
52
53 > Secondly, you're certianly not the first to wat to do data based archive
54 > pages. So far I have successfully punted the issue of creating these
55 > pages out of ikiwiki by pointing out that everyone wants them to be
56 > _different_, and suggesting people set up cron jobs or other machinery to
57 > generate the kinds of archives that they like. This makes me happy
58 > because generalizing all the possible ways people might want to do date
59 > based archives and somehow bolting support for creating them onto the
60 > size of ikiwiki seems to be a recipe for a mess. 
61
62 > A few examples of ikiwiki sites with date archives:
63 > <http://www.golden-gryphon.com/blog/manoj/> and
64 > <http://roland.entierement.nu/categories/geek-en.html> --[[Joey]]
65
66 >> Yeah, it wasn't much of a description, was it? ;-) It's an attempt to emulate the style of Wordpress and other popular blog platforms, which can link a post's creation date to  YYY/MM/DD archive pages, which then list all the relevant posts. My use-case is on a blog page which in-lines (via pagespecs) recent blog posts. 
67
68 >> I agree with not adding this kind of functionality to the core. :-) I simply didn't want to have break links when I convert to IkiWiki. I guess I'll just play around with the page-creation thing myself then. Feel free to delete this from the queue. :-) --Ben
69
70 >>> Ah, I get it, I hadn't realized it was making the date into a link.
71 >>> No reason to delete this from the queue, it's a reasonable plugin. I
72 >>> might move it to the contributed plugins directory as it's a bit
73 >>> specialised to be included in ikiwiki though. --[[Joey]]
74
75 [[tag patch]]