From 6ff61e52af5521901404b49d1c440b0223a2bd1f Mon Sep 17 00:00:00 2001 From: John SJ Anderson Date: Wed, 11 Mar 2015 14:35:23 -0700 Subject: [PATCH] Update plugins to create destination directories as needed. --- Changes | 1 + lib/HiD/Generator.pm | 12 ++++++++++++ lib/HiD/Generator/ArchivePage.pm | 1 + lib/HiD/Generator/CategoryPages.pm | 2 ++ lib/HiD/Generator/TagPages.pm | 2 ++ 5 files changed, 18 insertions(+) diff --git a/Changes b/Changes index 9b66d55..3dffa01 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for {{$dist->name}} {{$NEXT}} + Update plugins to create destination directories as needed. Update ArchivePage plugin. Update Tags plugin. Update AtomFeed plugin. diff --git a/lib/HiD/Generator.pm b/lib/HiD/Generator.pm index 3de4ce7..3c28f0f 100644 --- a/lib/HiD/Generator.pm +++ b/lib/HiD/Generator.pm @@ -34,5 +34,17 @@ requires 'generate'; =cut +sub _create_destination_directory_if_needed { + my( $self , $dest ) = @_; + + if ( -e $dest ) { + $self->FATAL( "'$dest' exists and is not a directory!" ) + unless -d $dest; + } + else { mkdir $dest } + + return 1; +} + no Moose::Role; 1; diff --git a/lib/HiD/Generator/ArchivePage.pm b/lib/HiD/Generator/ArchivePage.pm index fb22400..8c823d1 100644 --- a/lib/HiD/Generator/ArchivePage.pm +++ b/lib/HiD/Generator/ArchivePage.pm @@ -35,6 +35,7 @@ sub generate { my $destination = $site->config->{archive_page}{destination} // $site->destination; + $self->_create_destination_directory_if_needed( $destination ); my %archive = ( by_year => {} , diff --git a/lib/HiD/Generator/CategoryPages.pm b/lib/HiD/Generator/CategoryPages.pm index eb280fb..143d1f1 100644 --- a/lib/HiD/Generator/CategoryPages.pm +++ b/lib/HiD/Generator/CategoryPages.pm @@ -53,6 +53,8 @@ sub generate { my $destination = $self->destination // $site->destination; + $self->_create_destination_directory_if_needed( $destination ); + foreach my $category ( keys %{ $site->categories } ) { my $page = HiD::Page->new({ dest_dir => $destination , diff --git a/lib/HiD/Generator/TagPages.pm b/lib/HiD/Generator/TagPages.pm index 0a2ef27..0626203 100644 --- a/lib/HiD/Generator/TagPages.pm +++ b/lib/HiD/Generator/TagPages.pm @@ -40,6 +40,8 @@ sub generate { my $destination = $site->config->{tags}{destination} // $site->destination; + $self->_create_destination_directory_if_needed( $destination ); + foreach my $tag ( keys %{ $site->tags } ) { my $page = HiD::Page->new({ dest_dir => $destination ,