Skip to content

Commit

Permalink
allow for old events file
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed May 10, 2021
1 parent 73f3b0d commit df91215
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
7 changes: 2 additions & 5 deletions bin/check.pl
Expand Up @@ -2,15 +2,12 @@
use warnings;
use File::Spec;
use File::Basename;
use lib File::Spec->catfile(
File::Basename::dirname(File::Spec->rel2abs($0)),
'..',
'lib');
use lib File::Spec->catfile( File::Basename::dirname( File::Spec->rel2abs($0) ), '..', 'lib' );

use Perl::Maven::Calendar;

# Verify calendar format
# Should the dates be in order?

Perl::Maven::Calendar::create_calendar(q{sites/en/events.json});
Perl::Maven::Calendar::create_calendar( q{sites/en/events.json}, q{sites/en/old_events.json} );

3 changes: 2 additions & 1 deletion lib/Perl/Maven.pm
Expand Up @@ -727,8 +727,9 @@ get '/sitemap.xml' => sub {

get '/events.ics' => sub {
content_type 'text/calendar';
my $old_file = path( mymaven->{root}, 'sites', mymaven->{lang}, 'old_events.json' );
my $filepath = path( mymaven->{root}, 'sites', mymaven->{lang}, 'events.json' );
return Perl::Maven::Calendar::create_calendar($filepath);
return Perl::Maven::Calendar::create_calendar( $filepath, $old_file );
};

get '/rss/:tag' => sub {
Expand Down
11 changes: 8 additions & 3 deletions lib/Perl/Maven/Calendar.pm
Expand Up @@ -13,15 +13,20 @@ use Cpanel::JSON::XS qw(encode_json decode_json);
use Path::Tiny qw(path);

sub create_calendar {
my ($filepath) = @_;
my ( $filepath, $old_file ) = @_;

my $modify_time = ( stat($filepath) )[9];

my $calendar = Data::ICal->new;
my $changed = DateTime->from_epoch( epoch => $modify_time );

my $events = decode_json( path($filepath)->slurp_utf8 );
for my $event (@$events) {
my @events;
for my $file ( $old_file, $filepath ) {
if ( -e $file ) {
push @events, @{ decode_json( path($file)->slurp_utf8 ) };
}
}
for my $event (@events) {
my $ical_event = Data::ICal::Entry::Event->new;
my $begin = DateTime->new( $event->{begin} );
my $duration = DateTime::Duration->new( $event->{duration} );
Expand Down

0 comments on commit df91215

Please sign in to comment.