X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/22100642099595cb2f7393044aa4be511ef9721c..6975f9e3f4e06fb55cc8c9795c503019d2e8d08b:/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn diff --git a/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn b/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn index c14c54869..a26433919 100644 --- a/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn +++ b/doc/todo/Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn @@ -1,61 +1,208 @@ -[[tag patch]] - -Here's a patch to the calendar plugin. If you specify an event preprocessor in a post, such as: - - [[event time="2008-06-24"]] - -That date will be used instead of the post creation time when displaying the calendar. - - --- calendar.pm.orig 2008-06-24 22:36:09.000000000 -0400 - +++ calendar.pm 2008-06-24 22:51:11.000000000 -0400 - @@ -23,6 +23,7 @@ - use IkiWiki 2.00; - use Time::Local; - use POSIX; - +use Date::Parse; - - my %cache; - my %linkcache; - @@ -32,6 +33,7 @@ - sub import { #{{{ - hook(type => "needsbuild", id => "version", call => \&needsbuild); - hook(type => "preprocess", id => "calendar", call => \&preprocess); - + hook(type => "preprocess", id => "event", call => \&preprocess_event); - } #}}} - - sub is_leap_year (@) { #{{{ - @@ -304,6 +306,19 @@ - return $calendar; - } #}}} - - +sub preprocess_event (@) { #{{{ - + my %params=@_; - + # if now time is given, use now - + $params{time} = localtime unless defined $params{time}; - + - + my $timestamp = str2time($params{time}); - + if ( defined $timestamp) { - + $pagestate{$params{page}}{event}{mtime}=$timestamp; - + } - + # remove the event block entirely - + return ""; - +} #}} - + - sub preprocess (@) { #{{{ - my %params=@_; - $params{pages} = "*" unless defined $params{pages}; - @@ -355,7 +370,13 @@ - if (! defined $cache{$pagespec}) { - foreach my $p (keys %pagesources) { - next unless pagespec_match($p, $pagespec); - - my $mtime = $IkiWiki::pagectime{$p}; - + my $mtime; - + # use time defined by event preprocessor if it's available - + if (defined $pagestate{$p}{event}{mtime}) { - + $mtime = $pagestate{$p}{event}{mtime}; - + } else { - + $mtime = $IkiWiki::pagectime{$p}; - + } - my $src = $pagesources{$p}; - my @date = localtime($mtime); - my $mday = $date[3]; +[[!tag patch]] + +Here's my next version of the patch - still a work in progress. + +It provides the following new features. The features are designed to preserve the behavior of the existing plugin by default. + + * If you specify an event preprocessor in a post, such as: + + [[!event time="2008-06-24"]] + + That date will be used instead of the post creation time when displaying the calendar. + + * When specifying a calendar preprocessor, you can now add the following new parameters: + + * time_src: by default it is set to auto. auto means that when determining the date to use for a given post, take the date given in the event preprocessor directive if it exists and if not, use the creation time of the post. The other option is event which means: take the date given in the event preprocessor directive. If there is not event preprocessor in a post, don't include the post. + * detail: by default it is set to 0. If set to 0, display the monthly calendar as a series of days. Each day is a link to the post on that day. If there is more than one post on a day, only one is linked to. If set to 1 - then display the title of each post on the day as a link to the post. Is 0 and 1 the best values here? On/Off? Yes/no? + +The following changes are in the works: + + * Switch to using HTML::CalendarMonth to create the html output + + * Display the start time when detail is set to 1. + +Longer term plans: + + * Support recurring events + + * Support for end time on events (including end time that is on a different day than the start time) + + * Convincing the world to switch to base 10 calendar system. + + + --- calendar.pm.orig 2008-06-24 22:36:09.000000000 -0400 + +++ calendar.pm 2008-06-28 22:02:15.000000000 -0400 + @@ -23,6 +23,8 @@ + use IkiWiki 2.00; + use Time::Local; + use POSIX; + +use Date::Parse; + +use Data::Dumper; + + my %cache; + my %linkcache; + @@ -32,6 +34,7 @@ + sub import { #{{{ + hook(type => "needsbuild", id => "version", call => \&needsbuild); + hook(type => "preprocess", id => "calendar", call => \&preprocess); + + hook(type => "preprocess", id => "event", call => \&preprocess_event); + } #}}} + + sub is_leap_year (@) { #{{{ + @@ -58,6 +61,7 @@ + my $nmonth = $params{nmonth}; + my $pyear = $params{pyear}; + my $nyear = $params{nyear}; + + my $detail = $params{detail}; + + my @list; + my $calendar="\n"; + @@ -153,33 +157,58 @@ + } + + my $tag; + + my $display_day; + my $mtag = sprintf("%02d", $month); + - if (defined $cache{$pagespec}{"$year/$mtag/$day"}) { + - if ($day == $today) { + + if ($day == $today) { + $tag='month-calendar-day-this-day'; + - } + - else { + - $tag='month-calendar-day-link'; + - } + - $calendar.=qq{\t\t