X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=events.pm;h=5994ba6571c94174bcae84d89c7d6f69eb5afbe2;hb=2f1b1e65025c07c2495c7df21f4aae482b2ed7fa;hp=6e0d1da3cfea7c00a8027c01148da9205aa32f8e;hpb=51377e1af6dd2c06c5e353b2804e7732926ecf9f;p=ikiwiki%2Fevents.git
diff --git a/events.pm b/events.pm
index 6e0d1da..5994ba6 100644
--- 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,11 +213,12 @@ sub event_of_page ($%) {
= htmllink
( $params{page}
, $params{destpage}
- , '/'.$tag
+ , $tag
, linktext => $title
, noimageinline => 1
, title => $title );
- add_depends($params{page}, $event, deptype('content'));
+ #add_depends($params{page}, $event, deptype('content'));
+ # NOTE: useless now that deptype('content') is default.
#add_depends($params{page}, $tag, deptype('content'));
# XXX: much too heavy :\ and midnight refresh may fix it anyway.
my $class = qq{$tag};
@@ -288,7 +291,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}
@@ -307,7 +310,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}
@@ -327,7 +330,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}
@@ -368,8 +371,8 @@ sub preprocess_day (@) {
= pagespec_match_list
( $params{page}
, $params{pages}
- , deptype => deptype("presence")
- # NOTE: add presence dependencies to update calendar when pages are added/removed
+ , deptype => deptype("content")
+ # NOTE: add content dependency to update calendar when pages are tagged
);
my $event_html
= event_html
@@ -414,13 +417,15 @@ sub preprocess_month (@) {
= pagespec_match_list
( $params{page}
, $params{pages}
- , deptype => deptype("presence")
- # NOTE: add presence dependencies to update calendar when pages are added/removed
+ , deptype => deptype("content")
+ # NOTE: add presence dependency to update calendar when pages are tagged
);
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 $day = $event->{date}->{day};
+ push @{$events_by_day{$day}}, $event
+ if defined $day;
}
my $t='
';
@@ -516,47 +521,58 @@ 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 =
+ ( day => $params{focus}->day()
+ , month => $params{focus}->month()
+ , year => $params{focus}->year()
+ );
+ if (defined $params{year} and $params{year} =~ m/^(\d+)$/) {
+ my ($year) = ($1);
+ $focus_set{year} = $year;
+ }
+ if (defined $params{month} and $params{month} =~ m/^(\d+)$/ and ($params{type} eq 'month' or $params{type} eq 'day')) {
+ my ($month) = ($1);
+ $focus_set{month} = $month;
+ }
+ if (defined $params{day} and $params{day} =~ m/^(\d+)$/ and $params{type} eq 'day') {
+ my ($day) = ($1);
+ $focus_set{day} = $day;
+ }
+ if (not defined $focus_set{day}) {
+ $focus_set{day} = 1;
}
else {
- #$params{focus}->set(day => 1);
+ my $month = DateTime->new(year => $focus_set{year}, month => $focus_set{month}, day => 1);
+ my $last_day_of_month = $month->add(months => 1)->subtract(days => 1)->day();
+ $focus_set{day} = $last_day_of_month
+ if $focus_set{day} > $last_day_of_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});
- }
+ $params{focus}->set(%focus_set);
+
+ if (defined $params{day} and $params{day} =~ m/^([+-])(\d+)$/ and $params{type} eq 'day') {
+ 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{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});
- }
+ if (defined $params{month} and $params{month} =~ m/^([+-])(\d+)$/ and ($params{type} eq 'month' or $params{type} eq 'day')) {
+ 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'));