From: Julien Moutinho Date: Mon, 7 Apr 2014 23:50:09 +0000 (+0200) Subject: fix date_of_page() X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/Special:BookSources/%40%20%27info_articles_miens%27%20=%3E%20%27My%20articles%27%2C%20%27info_articles_tous%27%20=%3E%20%27All%20the%20articles%27%2C%20%27info_articles_trouves%27%20=%3E%20%27Articles%20found%27%2C-%27info_articles_trouves_dans_texte%27%20=%3E%20%27Articles%20found%20%28in%20the%20text%29%27%2C%20%27info_attente_validation%27%20=%3E%20%27Your%20articles%20awaiting%20validation%27%2C%20%27info_aucun_article%27%20=%3E%20%27No%20articles%27%2C-%27info_aucun_article_syndique%27%20=%3E%20%27No%20syndicated%20articles%27%2C%20%27info_aucun_auteur%27%20=%3E%20%27No%20authors%27%2C%20%27info_aucun_message%27%20=%3E%20%27No%20messages%27%2C%20%27info_aucun_rubrique%27%20=%3E%20%27No%20sections%27%2C-%27info_aucun_site%27%20=%3E%20%27No%20linked%20sites%27%2C-%27info_aucun_visiteur%27%20=%3E%20%27No%20visitors%27%2C%20%27info_aujourdhui%27%20=%3E%20%27today:%27%2C-%27info_auteur_message%27%20=%3E%20%27MESSAGE%20FROM:%27%2C%20%27info_auteurs%27%20=%3E%20%27Authors%27%2C%20%27info_auteurs_par_tri%27%20=%3E%20%27Authors%40partri%40%27%2C%20%27info_auteurs_trouves%27%20=%3E%20%27Authors%20found%27%2C%40%40%20-298%2C8%20%20254%2C6%20%40%40%20Do%20not%20submit%20this%20import%20request.%3Cp%3EFor%20more%20information%2C%20please%20see%20%3Ca%20href=?a=commitdiff_plain;h=e518be4f1f73ddc3b2443f0a6e9f21b8524a21f9;p=ikiwiki%2Fevents.git fix date_of_page() --- diff --git a/events.pm b/events.pm index ff3a539..51c176d 100644 --- a/events.pm +++ b/events.pm @@ -155,11 +155,15 @@ sub date_of_page ($%) { my $dir = IkiWiki::dirname($page); my ($year, $month, $day, $hour, $hour_begin, $hour_end) = $dir =~ m{ - .*/ - (\d+)/ - (01|02|03|04|05|06|07|08|09|10|11|12)/ - (01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)/ - (([0-2][0-9]h[0-5][0-9])(-[0-2][0-9]h[0-5][0-9])?)? + .*? + /(\d+) + (?:/(01|02|03|04|05|06|07|08|09|10|11|12) + (?:/(01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31) + (?:/(([0-2][0-9]h[0-5][0-9]) + (?:-([0-2][0-9]h[0-5][0-9]))?) + )? + )? + )? $ }x; my $r = @@ -174,13 +178,13 @@ sub date_of_page ($%) { return $r; } sub event_of_page ($%) { - my ($event, %params) = @_; + my ($event, $date, %params) = @_; my $title = exists $pagestate{$event}{meta}{title} ? $pagestate{$event}{meta}{title} : pagetitle(IkiWiki::basename($event)); my $hour - = date_of_page($event)->{hour}; + = $date->{hour}; my $link = htmllink ( $params{page} @@ -223,6 +227,8 @@ sub event_of_page ($%) { $base =~ s/[^a-zA-Z0-9-]/_/g; return { hour => $hour + , page => $event + , date => $date , link => $link , tags => \@tags , base => $base }; @@ -235,16 +241,16 @@ sub events_of_pages ($%) { foreach my $page (@$pages) { my $date = date_of_page($page); if (defined $date->{hour}) { - push @hour_events, $page; + push @hour_events, {page=>$page, date=>$date}; } else { - push @day_events, $page; + push @day_events, {page=>$page, date=>$date}; } } return - map {event_of_page($_, %params)} - ( (sort {lc $pagedir->($a) cmp lc $pagedir->($b)} @day_events) - , (sort {lc $pagedir->($a) cmp lc $pagedir->($b)} @hour_events) ); + map {event_of_page($_->{page}, $_->{date}, %params)} + ( (sort {lc IkiWiki::basename($a->{page}) cmp lc IkiWiki::basename($b->{page})} @day_events) + , (sort {lc $a->{hour}.'/'.IkiWiki::basename($a->{page}) cmp lc $b->{hour}.'/'.IkiWiki::basename($b->{page})} @hour_events) ); } sub event_html ($$%) { my ($date, $format, %params) = @_; @@ -408,15 +414,9 @@ sub preprocess_month (@) { # NOTE: add presence dependencies to update calendar when pages are added/removed ); - # NOTE: sort the pages by days of the month - my %days = map {($_=>[])} (1 .. $last_day); - foreach my $page (@pages) { - my $page_ctime = DateTime->from_epoch - ( epoch => $IkiWiki::pagectime{$page} - , time_zone => 'local' - , locale => $config{locale} - ); - push @{$days{$page_ctime->day()}}, $page; + my %events_by_day = map {($_=>[])} (1 .. $last_day); + foreach my $event (events_of_pages(\@pages, %params)) { + push @{$events_by_day{$event->{date}->{day}}}, $event; } my $t=''; @@ -448,7 +448,7 @@ sub preprocess_month (@) { . "" . "\n" } - events_of_pages($days{$day->day()}, %params); + @{$events_by_day{sprintf('%02d',$day->day())}}; $t .= "" . "" @@ -496,6 +496,10 @@ sub preprocess_month (@) { sub preprocess (@) { my %params = @_; $params{focus} = $now->clone; + $params{focus}->set_hour(0); + $params{focus}->set_minute(0); + $params{focus}->set_second(0); + $params{focus}->set_nanosecond(0); $params{pages} = "*" unless defined $params{pages}; $params{type} = "month" unless defined $params{type};