fix wrong tag page
[ikiwiki/events.git] / events.pm
index 51c176d..2820c60 100644 (file)
--- a/events.pm
+++ b/events.pm
@@ -202,7 +202,9 @@ sub event_of_page ($%) {
                 (keys %{$IkiWiki::typedlinks{$event}{tag}}));
        @tags
         = map {
-               my $tag = $_;
+               my $tag_best = bestlink($params{page}, $_);
+               $tag_best = (length $tag_best > 0 ? $tag_best : bestlink($event, $_));
+               my $tag = (length $tag_best > 0 ? $tag_best : $_);
                my $title
                 = exists $pagestate{$tag}{meta}{title}
                 ? $pagestate{$tag}{meta}{title}
@@ -211,7 +213,7 @@ sub event_of_page ($%) {
                 = htmllink
                 ( $params{page}
                 , $params{destpage}
-                , '/'.$tag
+                , $tag
                 , linktext => $title
                 , noimageinline => 1
                 , title => $title );
@@ -250,7 +252,11 @@ sub events_of_pages ($%) {
        return
         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) );
+        , (sort {
+               my $r = $a->{date}->{hour} cmp $b->{date}->{hour};
+               if ($r) { $r }
+               else { IkiWiki::basename($a->{page}) cmp IkiWiki::basename($b->{page}) }
+        } @hour_events) );
  }
 sub event_html ($$%) {
        my ($date, $format, %params) = @_;
@@ -284,7 +290,7 @@ sub event_html ($$%) {
                         , $date->year()
                         );
                        add_depends($params{page}, $year_page, deptype("presence"));
-                       if ($pagesources{$year_page}) {
+                       if (exists $pagesources{$year_page}) {
                                $year_html
                                 = htmllink
                                 ( $params{page}
@@ -303,7 +309,7 @@ sub event_html ($$%) {
                         , $date->month()
                         );
                        add_depends($params{page}, $month_page, deptype("presence"));
-                       if ($pagesources{$month_page}) {
+                       if (exists $pagesources{$month_page}) {
                                $month_html
                                 = htmllink
                                 ( $params{page}
@@ -323,7 +329,7 @@ sub event_html ($$%) {
                         , $date->day()
                         );
                        add_depends($params{page}, $day_page, deptype("presence"));
-                       if ($pagesources{$day_page}) {
+                       if (exists $pagesources{$day_page}) {
                                $day_html
                                 = htmllink
                                 ( $params{page}
@@ -512,47 +518,45 @@ sub preprocess (@) {
                 ? $config{events_base}
                 : gettext('Agenda');
         }
-       if (defined $params{day}) {
-               if ($params{day} =~ m/^([+-])(\d+)$/) {
-                       my ($sign, $days) = ($1, $2);
-                       my $duration = DateTime::Duration->new(days => $days, end_of_month => 'limit');
-                       $params{focus}
-                        = $sign eq '+'
-                        ? $params{focus}->add_duration($duration)
-                        : $params{focus}->subtract_duration($duration);
-                }
-               else {
-                       $params{focus}->set(day => $params{day});
-                }
+       
+       my %focus_set;
+       if (defined $params{day} and $params{day} =~ m/^(\d+)$/) {
+               my ($day) = ($1);
+               $focus_set{day} = $day;
         }
-       else {
-               #$params{focus}->set(day => 1);
+       if (defined $params{month} and $params{month} =~ m/^(\d+)$/) {
+               my ($month) = ($1);
+               $focus_set{month} = $month;
         }
-       if (defined $params{month}) {
-               if ($params{month} =~ m/^([+-])(\d+)$/) {
-                       my ($sign, $months) = ($1, $2);
-                       my $duration = DateTime::Duration->new(months => $months, end_of_month => 'limit');
-                       $params{focus}
-                        = $sign eq '+'
-                        ? $params{focus}->add_duration($duration)
-                        : $params{focus}->subtract_duration($duration);
-                }
-               else {
-                       $params{focus}->set(month => $params{month});
-                }
+       if (defined $params{year} and $params{year} =~ m/^(\d+)$/) {
+               my ($year) = ($1);
+               $focus_set{year} = $year;
         }
-       if (defined $params{year}) {
-               if ($params{year} =~ m/^([+-])(\d+)$/) {
-                       my ($sign, $years) = ($1, $2);
-                       my $duration = DateTime::Duration->new(years => $years, end_of_month => 'limit');
-                       $params{focus}
-                        = $sign eq '+'
-                        ? $params{focus}->add_duration($duration)
-                        : $params{focus}->subtract_duration($duration);
-                }
-               else {
-                       $params{focus}->set(year => $params{year});
-                }
+       $params{focus}->set(%focus_set);
+       
+       if (defined $params{day} and $params{day} =~ m/^([+-])(\d+)$/) {
+               my ($sign, $days) = ($1, $2);
+               my $duration = DateTime::Duration->new(days => $days, end_of_month => 'limit');
+               $params{focus}
+                = $sign eq '+'
+                ? $params{focus}->add_duration($duration)
+                : $params{focus}->subtract_duration($duration);
+        }
+       if (defined $params{month} and $params{month} =~ m/^([+-])(\d+)$/) {
+               my ($sign, $months) = ($1, $2);
+               my $duration = DateTime::Duration->new(months => $months, end_of_month => 'limit');
+               $params{focus}
+                = $sign eq '+'
+                ? $params{focus}->add_duration($duration)
+                : $params{focus}->subtract_duration($duration);
+        }
+       if (defined $params{year} and $params{year} =~ m/^([+-])(\d+)$/) {
+               my ($sign, $years) = ($1, $2);
+               my $duration = DateTime::Duration->new(years => $years, end_of_month => 'limit');
+               $params{focus}
+                = $sign eq '+'
+                ? $params{focus}->add_duration($duration)
+                : $params{focus}->subtract_duration($duration);
         }
        
        #debug("events: focus=".$params{focus}->strftime('%Y-%m-%d_%H-%M-%S'));