~duncan-bayne/halp

2659067e3ea8c5b29b8891e82bedda7e02056845 — Duncan Bayne 1 year, 3 months ago 3c65579
Fix web path handling in Atom generation
3 files changed, 10 insertions(+), 8 deletions(-)

M lib/Halp/AtomFeed.pm
M lib/Halp/WebServer.pm
M t/Halp/atom_feed_test.t
M lib/Halp/AtomFeed.pm => lib/Halp/AtomFeed.pm +3 -6
@@ 14,19 14,16 @@ our @EXPORT = qw(feed_for);
sub feed_for {
    my ($request_path, $local_path, $web_path, $domain, $author) = @_;

    my $directory_name = dirname($local_path);
    my $feed_path = dirname($request_path);

    my $feed_directory = File::Spec->catfile($web_path, dirname($feed_path));
    my $feed_directory = File::Spec->catfile($web_path, dirname($local_path));
    my $updated_at = `cd $feed_directory; git log --reverse --pretty='format:%ad' --date=iso8601-strict -- | head -1`;

    my $feed = XML::Atom::SimpleFeed->new(
	title   => directory_title($directory_name),
	title   => directory_title($feed_directory),
	link    => "https://$domain$feed_path",
	updated => $updated_at
	);

    my @files = directory_listing($feed_path, $directory_name, 1);
    my @files = directory_listing($request_path, $feed_directory, 1);

    foreach my $file (@files) {
	my $full_path = $file->{filename};

M lib/Halp/WebServer.pm => lib/Halp/WebServer.pm +5 -1
@@ 149,7 149,11 @@ sub handle_file {
sub handle_atom_feed {
    my ($self, $request_path, $local_path) = @_;

    my $atom_feed = feed_for($request_path, $local_path, $web_path, $self->{domain}, $self->{author});
    print STDERR "+++ request_path $request_path\n";
    print STDERR "+++ local_path $local_path\n";
    print STDERR "+++ web_path $self->{web_path}\n";

    my $atom_feed = feed_for($request_path, $local_path, $self->{web_path}, $self->{domain}, $self->{author});
    return {content_type => 'application/xml+atom', content => $atom_feed};
}


M t/Halp/atom_feed_test.t => t/Halp/atom_feed_test.t +2 -1
@@ 4,13 4,14 @@ use lib cwd() . '/lib';
use strict;
use warnings;

use File::Spec::Functions 'rel2abs';
use Halp::AtomFeed;
use Mojo::DOM;
use Test::More;

use Test::More tests => 8;

my $feed = feed_for('/atom_feed/feed.xml', './t/fixtures/atom_feed/feed.xml', '.', 'example.com', {email => 'author@example.com', name => 'An Author'});
my $feed = feed_for('/atom_feed/feed.xml', './t/fixtures/atom_feed/feed.xml', rel2abs('.'), 'example.com', {email => 'author@example.com', name => 'An Author'});
my $xml = Mojo::DOM->new->xml(1)->parse($feed);

is($xml->at('feed')->at('title')->text, 'Test Title', 'The Atom feed has the correct title.');