aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/aggregate.pm35
-rw-r--r--IkiWiki/Render.pm28
2 files changed, 45 insertions, 18 deletions
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 2e1ab66e6..973f7a4ca 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -34,6 +34,7 @@ sub checkconfig () { #{{{
if ($config{aggregate}) {
IkiWiki::loadindex();
aggregate();
+ expire();
savestate();
}
IkiWiki::unlockwiki();
@@ -79,6 +80,7 @@ sub preprocess (@) { #{{{
$feed->{expireage}=defined $params{expireage} ? $params{expireage} : 0;
$feed->{expirecount}=defined $params{expirecount} ? $params{expirecount} : 0;
delete $feed->{remove};
+ delete $feed->{expired};
$feed->{lastupdate}=0 unless defined $feed->{lastupdate};
$feed->{numposts}=0 unless defined $feed->{numposts};
$feed->{newposts}=0 unless defined $feed->{newposts};
@@ -164,6 +166,11 @@ sub savestate () { #{{{
}
next;
}
+ elsif ($data->{expired} && exists $data->{page}) {
+ unlink pagefile($data->{page});
+ delete $data->{page};
+ delete $data->{md5};
+ }
my @line;
foreach my $field (keys %$data) {
@@ -183,6 +190,32 @@ sub savestate () { #{{{
close OUT;
} #}}}
+sub expire () { #{{{
+ foreach my $feed (values %feeds) {
+ next unless $feed->{expireage} || $feed->{expirecount};
+ my $count=0;
+ foreach my $item (sort { $IkiWiki::pagectime{$b->{page}} <=> $IkiWiki::pagectime{$a->{page}} }
+ grep { exists $_->{page} && $_->{feed} eq $feed->{name} && $IkiWiki::pagectime{$_->{page}} }
+ values %guids) {
+ if ($feed->{expireage}) {
+ my $days_old = (time - $IkiWiki::pagectime{$item->{page}}) / 60 / 60 / 24;
+ if ($days_old > $feed->{expireage}) {
+ debug("expiring ".$item->{page}." ($days_old days old)");
+ $item->{expired}=1;
+ }
+ }
+ elsif ($feed->{expirecount} &&
+ $count >= $feed->{expirecount}) {
+ debug("expiring ".$item->{page});
+ $item->{expired}=1;
+ }
+ else {
+ $count++;
+ }
+ }
+ }
+} #}}}
+
sub aggregate () { #{{{
eval q{use XML::Feed};
die $@ if $@;
@@ -237,8 +270,6 @@ sub aggregate () { #{{{
displaytime($feed->{lastupdate});
$feed->{error}=0;
}
-
- # TODO: expiry
} #}}}
sub add_page (@) { #{{{
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index f59e54f29..5b951df83 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -11,6 +11,7 @@ my %backlinks;
my $backlinks_calculated=0;
sub calculate_backlinks () { #{{{
+ return if $backlinks_calculated;
%backlinks=();
foreach my $page (keys %links) {
foreach my $link (@{$links{$page}}) {
@@ -26,7 +27,7 @@ sub calculate_backlinks () { #{{{
sub backlinks ($) { #{{{
my $page=shift;
- calculate_backlinks() unless $backlinks_calculated;
+ calculate_backlinks();
my @links;
return unless $backlinks{$page};
@@ -303,6 +304,7 @@ sub refresh () { #{{{
scan($file);
}
}
+ calculate_backlinks();
# render changed and new pages
foreach my $file (@changed) {
@@ -311,22 +313,16 @@ sub refresh () { #{{{
$rendered{$file}=1;
}
- # if any files were added or removed, check to see if each page
- # needs an update due to linking to them or inlining them
+ # rebuild pages that link to added or removed pages
if (@add || @del) {
-FILE: foreach my $file (@files) {
- next if $rendered{$file};
- my $page=pagename($file);
- foreach my $f (@add, @del) {
- my $p=pagename($f);
- foreach my $link (@{$links{$page}}) {
- if (bestlink($page, $link) eq $p) {
- debug("rendering $file, which links to $p");
- render($file);
- $rendered{$file}=1;
- next FILE;
- }
- }
+ foreach my $f (@add, @del) {
+ my $p=pagename($f);
+ foreach my $page (keys %{$backlinks{$p}}) {
+ my $file=$pagesources{$page};
+ next if $rendered{$file};
+ debug("rendering $file, which links to $p");
+ render($file);
+ $rendered{$file}=1;
}
}
}