]> sipb.mit.edu Git - ikiwiki.git/commitdiff
calendar: Allow negative month to be specified. -1 is last month, etc. (And also...
authorJoey Hess <joey@kitenet.net>
Sat, 8 May 2010 16:45:21 +0000 (12:45 -0400)
committerJoey Hess <joey@kitenet.net>
Sat, 8 May 2010 16:45:21 +0000 (12:45 -0400)
IkiWiki/Plugin/calendar.pm
debian/changelog
doc/ikiwiki/directive/calendar.mdwn
doc/plugins/calendar/discussion.mdwn

index aeb5f3d294693b93285fac9da87ab2564bd89add..02f41070e10ae6acf29ce9abd3c52aead7aefbc4 100644 (file)
@@ -386,8 +386,19 @@ sub preprocess (@) {
        $params{year}  = $thisyear      unless defined $params{year};
        $params{month} = $thismonth     unless defined $params{month};
 
+       my $relativemonth=0;
+       if ($params{month} < 1) {
+               $params{month}=$thismonth+$params{month};
+               $relativemonth=1;
+       }
+       my $relativeyear=0;
+       if ($params{year} < 1) {
+               $params{year}=$thisyear+$params{year};
+               $relativeyear=1;
+       }
+       
        $params{month} = sprintf("%02d", $params{month});
-                       
+       
        if ($params{type} eq 'month' && $params{year} == $thisyear
            && $params{month} == $thismonth) {
                # calendar for current month, updates next midnight
@@ -404,8 +415,11 @@ sub preprocess (@) {
                $pagestate{$params{destpage}}{calendar}{nextchange}=
                        timelocal(0, 0, 0, 1, $params{month}-1, $params{year});
        }
-       elsif ($params{type} eq 'year' && $params{year} == $thisyear) {
-               # calendar for current year, updates 1st of next month
+       elsif (($params{type} eq 'year' && $params{year} == $thisyear) ||
+              $relativemonth) {
+               # Calendar for current year updates 1st of next month.
+               # Any calendar relative to the current month also updates
+               # then.
                if ($thismonth < 12) {
                        $pagestate{$params{destpage}}{calendar}{nextchange}=
                                timelocal(0, 0, 0, 1, $thismonth+1-1, $params{year});
@@ -415,6 +429,12 @@ sub preprocess (@) {
                                timelocal(0, 0, 0, 1, 1-1, $params{year}+1);
                }
        }
+       elsif ($relativeyear) {
+               # Any calendar relative to the current year updates 1st
+               # of next year.
+               $pagestate{$params{destpage}}{calendar}{nextchange}=
+                       timelocal(0, 0, 0, 1, 1-1, $thisyear+1);
+       }
        elsif ($params{type} eq 'year' && $params{year} > $thisyear) {
                # calendar for upcoming year, updates 1st of that year
                $pagestate{$params{destpage}}{calendar}{nextchange}=
@@ -426,7 +446,6 @@ sub preprocess (@) {
                delete $pagestate{$params{destpage}}{calendar};
        }
 
-       # Calculate month names for next month, and previous months
        my $calendar="";
        if ($params{type} eq 'month') {
                $calendar=format_month(%params);
index f74e9929fda1ea6cfc8474265a69641368112809..795f02822f1a02575f16053e0eff82717a4b8cb4 100644 (file)
@@ -26,6 +26,8 @@ ikiwiki (3.20100505) UNRELEASED; urgency=low
     leave passwordauth enabled and let people who don't have an openid use it.
     The openid selector form avoids the UI annoyance of having both openid
     and passwordauth on one form.
+  * calendar: Allow negative month to be specified. -1 is last month, etc.
+    (And also negaitve years.)
 
  -- Joey Hess <joeyh@debian.org>  Wed, 05 May 2010 18:07:29 -0400
 
index 198da9d51c33cef97bbf2884b6c77b27e5137419..e9216e11fd5f8b8e691db473b92a2d1b05e88f10 100644 (file)
@@ -47,14 +47,14 @@ An example crontab:
   "2010". These pages can be automatically created using the
   `ikiwiki-calendar` program. 
 * `year` - The year for which the calendar is requested. Defaults to the
-  current year.
+  current year. Can also use -1 to refer to last year, and so on.
 * `month` - The numeric month for which the calendar is requested, in the
   range 1..12. Used only for the month view calendar, and defaults to the
-  current month.
+  current month. Can also use -1 to refer to last month, and so on.
 * `week_start_day` - A number, in the range 0..6, which represents the day
   of the week that the month calendar starts with. 0 is Sunday, 1 is Monday,
   and so on. Defaults to 0, which is Sunday.
-* `months_per_row` - In the annual calendar, number of months to place in
+* `months_per_row` - In the year calendar, number of months to place in
   each row. Defaults to 3.
 
 [[!meta robots="noindex, follow"]]
index 9d57b7a1e6526d12846816f71531808be10940dd..bb76a9d8be426418815074aa0c0ae5db3ac68658 100644 (file)
@@ -1,6 +1,15 @@
 It would be nice if the "month" type calendar could collect all of the 
 matching pages on a given date in some inline type way. --[[DavidBremner]]
 
+> I agree, but I have not come up with good html to display them. Seems 
+> it might need some sort of popup.
+
 Is it possible to get the calendar to link to pages based not on their timestamp (as I understand that it does now, or have I misunderstood this?) and instead on for example their location in a directory hierarchy. That way the calendar could be used as a planning / timeline device which I think would be great. --[[Alexander]]
 
-I would like the ability to specify relative previous months. This way I could have a sidebar with the last three months by specifying no month, then 'month="-1"' and 'month="-2"'. Negative numbers for the month would otherwise be invalid, so this shouldn't produce any conflicts with expected behavior. (Right?) -- [[StevenBlack]]
+I would like the ability to specify relative previous months. This way I
+could have a sidebar with the last three months by specifying no month,
+then 'month="-1"' and 'month="-2"'. Negative numbers for the month would
+otherwise be invalid, so this shouldn't produce any conflicts with expected
+behavior. (Right?) -- [[StevenBlack]]
+
+> Great idea! Just implemented that and also relative years. --[[Joey]]