From deaa98d0f80df046ee53f55a54b847ebf2161ce6 Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Fri, 14 Jun 2024 11:27:48 +0100 Subject: [PATCH] Add uri() method to file class. --- lib/App/Aphra/File.pm | 14 ++++++++++++++ t/data1/site.yml | 1 + 2 files changed, 15 insertions(+) diff --git a/lib/App/Aphra/File.pm b/lib/App/Aphra/File.pm index 99563a4..306f7ab 100644 --- a/lib/App/Aphra/File.pm +++ b/lib/App/Aphra/File.pm @@ -7,6 +7,7 @@ use File::Path 'make_path'; use File::Copy; use Text::FrontMatter::YAML; use Path::Tiny (); +use URI; has [qw[path name extension ]] => ( isa => 'Str', @@ -88,6 +89,19 @@ sub full_name { return $full_name; } +sub uri { + my $self = shift; + + my $uri = $self->app->uri; + my $path = $self->destination_dir; + my $base = $self->app->site_vars->{base}; + $path =~ s/^$base//; + $uri .= $path . $self->output_name; + $uri =~ s/index\.html$//; + + return URI->new($uri); +} + sub process { my $self = shift; diff --git a/t/data1/site.yml b/t/data1/site.yml index a21deb7..4849500 100644 --- a/t/data1/site.yml +++ b/t/data1/site.yml @@ -1 +1,2 @@ uri : https://example.com/ +base : docs