From 51cf3391db28f464f82df85e2a20bafb448237d3 Mon Sep 17 00:00:00 2001 From: Matthew Connelly Date: Wed, 11 Mar 2015 21:32:50 +0000 Subject: [PATCH] add rss generation? maybe??? --- blogalba | 36 +++++++++++++++++++++++++++++++----- config | 1 + 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/blogalba b/blogalba index 12b5a02..f80c812 100755 --- a/blogalba +++ b/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}? '' : '', ); + generate_feed; pagination_calc; } diff --git a/config b/config index 6360647..9f6d2fa 100644 --- a/config +++ b/config @@ -9,6 +9,7 @@ posturlprepend: wrote/ config: indexable: 1 per_page: 6 + rss_posts: 8 date_format: "%H:%M on %A, %d/%m/%y" links: Twitter: https://twitter.com/maffsie