add rss generation? maybe???
This commit is contained in:
parent
dc83283feb
commit
51cf3391db
36
blogalba
36
blogalba
|
@ -7,14 +7,16 @@ use strict;
|
|||
use warnings;
|
||||
use feature qw/say/;
|
||||
|
||||
use POSIX qw/strftime/;
|
||||
use Date::Parse qw/str2time/;
|
||||
use File::Spec;
|
||||
use HTML::Template;
|
||||
use Text::MultiMarkdown qw/markdown/;
|
||||
use Unicode::Normalize;
|
||||
use YAML;
|
||||
|
||||
use POSIX qw/strftime/;
|
||||
use Date::Parse qw/str2time/; #Required for converting the date field in posts to something strftime can work with
|
||||
use XML::RSS;
|
||||
use Unicode::Normalize;
|
||||
|
||||
use Dancer2;
|
||||
|
||||
my $ME = 'BlogAlba'; my $ME_GH = 'https://github.com/MaffC/BlogAlba/';
|
||||
|
@ -114,7 +116,30 @@ sub get_page {
|
|||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub generate_feed {
|
||||
my $feed = new XML::RSS(version => '2.0');
|
||||
$feed->channel (
|
||||
title => $blog->{name},
|
||||
link => $blog->{url},
|
||||
description => $blog->{tagline},
|
||||
dc => {
|
||||
creator => $blog->{author},
|
||||
language => "en-gb",
|
||||
},
|
||||
syn => {
|
||||
updatePeriod => "daily",
|
||||
updateFrequency => "1",
|
||||
updateBase => "1970-01-01T00:00+00:00",
|
||||
},
|
||||
);
|
||||
$feed->add_item (
|
||||
title => $_->{title},
|
||||
link => $_->{permaurl},
|
||||
description => $_->{excerpt},
|
||||
dc => { creator => $blog->{author}, },
|
||||
) for @posts[0 .. ($#posts > ($blog->{rss_posts}-1)? ($blog->{rss_posts}-1) : $#posts)];
|
||||
$feed->save("$basedir/public/rss.rdf");
|
||||
}
|
||||
sub do_cache {
|
||||
return if $lastcache > (time - 3600);
|
||||
$lastcache = time;
|
||||
|
@ -139,11 +164,12 @@ sub do_cache {
|
|||
push @nav, {navname => $_->{title}, navurl => "$blog->{url}$_->{filename}",} for @pages;
|
||||
push @nav, {navname => $_, navurl => $blog->{links}->{$_},} for sort {$b cmp $a } keys $blog->{links};
|
||||
%defparams = (
|
||||
INDEX => 0, NAV => [@nav], url => $blog->{url}, recent => [@posts[0 .. ($#posts > 7? 7 : $#posts)]],
|
||||
INDEX => 0, NAV => [@nav], url => $blog->{url}, recent => [@posts[0 .. ($#posts > ($blog->{rss_posts}-1)? ($blog->{rss_posts}-1) : $#posts)]],
|
||||
gentime => timefmt($lastcache, '%H:%M %e/%-m/%y %Z'), generator => $ME, generatorurl => $ME_GH, host => $HOST,
|
||||
about => $blog->{about}, author => $blog->{author}, name => $blog->{name}, tagline => $blog->{tagline}, keywords => $blog->{keywords},
|
||||
robots => $blog->{config}->{indexable}? '<meta name="ROBOTS" content="INDEX, FOLLOW" />' : '<meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />',
|
||||
);
|
||||
generate_feed;
|
||||
pagination_calc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue