1 [[!tag wishlist]]I would quite like the ability to write a page (blog post in
2 practice) but for the page to not be displayed until a date and time after it
3 is added to the wiki. I've thought this through a bit, but would appreciate
4 feedback from people before I go any further. Would anyone else find this
7 Thinking about how to implement this in ikiwiki, perhaps a conditional
8 pagespec would be best (which could be tidied up into a template)
10 [[!if test="current_date_before(<TMPL_VAR date>)"
11 then="""[[!tag draft]]"""
12 else="""[[!meta date="<TMPL_VAR date>"]]"""
15 …pre-supposing a scheme whereby tagging 'draft' hides the page from an
16 aggregation somewhere. With a template, this could collapse to
18 [[!template id=publishafter date="Thu Aug 30 14:13:06 BST 2012"]]
20 This would require implementing the `current_date_before` pagespec.
22 You would also need a regularly scheduled wiki refresh and a way of marking the
23 unpublished pages as 'dirty' so they were always scanned on refresh until their
24 publish date has occurred. That could perhaps be implemented via a small plugin
25 which defined a pagespec which ensured the page was 'dirty':
27 [[!if test="current_date_before(<TMPL_VAR date>)"
28 then="""[[!tag draft]][[!dirty]]"""
29 else="""[[!meta date="<TMPL_VAR date>"]]"""
32 The following is an attempt at the dirty part:
35 package IkiWiki::Plugin::dirty;
36 # provides a pagespec 'dirty' which ensures the page will always be
37 # re-scanned for content on wiki refresh.
43 hook(type => "preprocess", id => "dirty", call => \&preprocess);
44 hook(type => "needsbuild", id => "dirty", call => \&needsbuild);
48 $pagestate{$params{page}}{dirty}{dirty} = 1;
54 my %p2 = map { $_ => 1 } @$pages;
55 my %d2 = map { $_ => 1 } @$deleted;
57 foreach my $page (keys %pagestate) {
58 if(exists $pagestate{$page}{dirty}{dirty}) {
59 push @$pages, $pagesources{$page} unless
60 (exists $p2{$pagesources{$page}} or exists $d2{$pagesources{$page}});
61 delete $pagestate{$page}{dirty}{dirty};
70 Although it doesn't fit, the `current_date_before` pagespec could be implemented
71 in the same plugin. I tried the following (before the trailing `1`):
73 package IkiWiki::PageSpec;
76 sub match_current_date_before ($$;@) {
79 my $out = str2time($date);
81 return IkiWiki::SuccessReason->new("time before now") if $out < time();
82 return IkiWiki::FailReason->new("time not before now");
83 } else { return IkiWiki::ErrorReason->new("couldn't parse time $date")};
86 I always hit the `ErrorReason` branch when I try to use it, even with strings
87 which work fine in test scripts. If anyone can help me debug that I'd be very
89 If anyone has any clues as to why this doesn't work
91 Thoughts on the whole idea? — [[Jon]]