diff --git a/lib/Plerd.pm b/lib/Plerd.pm index eba0ec5..31ac8e3 100644 --- a/lib/Plerd.pm +++ b/lib/Plerd.pm @@ -562,7 +562,7 @@ sub publish_recent_page { $self->publication_directory, "index.html.$$.tmp" ); $temp_link->remove if -e $temp_link || -l $temp_link; - if ( symlink $self->recent_file, $temp_link ) { + if ( symlink $self->recent_file->basename, $temp_link ) { rename "$temp_link", "$index_file" or warn "Couldn't move the index.html symlink into place: $!\n"; } diff --git a/t/index_symlink.t b/t/index_symlink.t new file mode 100644 index 0000000..9df7af3 --- /dev/null +++ b/t/index_symlink.t @@ -0,0 +1,47 @@ +use warnings; +use strict; +use Test::More; +use Path::Class::Dir; +use Path::Class::File; +use URI; + +use FindBin; +use lib "$FindBin::Bin/../lib"; + +use_ok( 'Plerd' ); +use Plerd::Init; + +# Regression test for GitHub issue #54: the docroot/index.html symlink must +# point at its sibling "recent.html" by basename, not at a path that includes +# the docroot directory. A target like "docroot/recent.html" resolves to +# docroot/docroot/recent.html from inside docroot and leaves index.html broken. + +my $blog_dir = Path::Class::Dir->new( "$FindBin::Bin/index_symlink_blog" ); +$blog_dir->rmtree; +Plerd::Init::initialize( $blog_dir->stringify, 0 ); + +Path::Class::File->new( $blog_dir, 'source', '2021-01-01-hello.md' )->spew( + iomode => '>:encoding(utf8)', + "title: Hello\n\nBody.\n", +); + +my $plerd = Plerd->new( + path => $blog_dir->stringify, + title => 'Test Blog', + author_name => 'Nobody', + author_email => 'nobody@example.com', + base_uri => URI->new( 'http://blog.example.com/' ), +); + +$plerd->publish_all; + +my $index = Path::Class::File->new( $blog_dir, 'docroot', 'index.html' ); + +ok( -l $index, 'docroot/index.html is a symlink.' ); +is( readlink( "$index" ), 'recent.html', + 'index.html points at its sibling recent.html by basename.' ); +ok( -e $index, 'index.html resolves to an existing file.' ); + +$blog_dir->rmtree; + +done_testing();