diff --git a/lib/Qgoda.pm b/lib/Qgoda.pm index 4595f8e..25cb4ae 100644 --- a/lib/Qgoda.pm +++ b/lib/Qgoda.pm @@ -985,15 +985,21 @@ sub __prune { # Sort the output files by length first. That ensures that we do a # depth first clean-up. my @outfiles = sort { - length($b) <=> length($a) + length($b) <=> length($a) } @{$self->{__outfiles}}; my $logger = $self->{__logger}; my %directories; + my $outdir = $self->config->{paths}->{site}; + my $matcher = $self->config->{__q_precious}; my $deleted = 0; foreach my $outfile (@outfiles) { - if ($directories{$outfile} || $site->getArtefact($outfile)) { + my $reloutfile = abs2rel $outfile, $outdir; + if ($matcher->match($reloutfile)) { + $logger->debug(__x("not pruning precious file '{outfile}'", + outfile => $outfile)); + } elsif ($directories{$outfile} || $site->getArtefact($outfile)) { # Mark the containing directory as generated. my ($volume, $directory, $filename) = splitpath $outfile; my $container = catpath $volume, $directory, ''; diff --git a/lib/Qgoda/Config.pm b/lib/Qgoda/Config.pm index ddb7383..7ba9aad 100644 --- a/lib/Qgoda/Config.pm +++ b/lib/Qgoda/Config.pm @@ -28,6 +28,7 @@ use Scalar::Util qw(reftype looks_like_number); use File::Globstar qw(quotestar); use File::Globstar::ListMatch; use Storable qw(dclone); +use Cwd qw(realpath); use Encode; use boolean; use Qgoda::Util qw(read_file empty yaml_error merge_data lowercase @@ -160,7 +161,7 @@ sub new { # Clean up certain variables or overwrite them unconditionally. $config->{srcdir} = absolute_path; $config->{paths}->{site} = - canonical_path(absolute_path($config->{paths}->{site})); + canonical_path(absolute_path(realpath($config->{paths}->{site}))); $config->{paths}->{views} = canonical_path($config->{paths}->{views}); $config->{po}->{tt2} = [$config->{paths}->{views}] @@ -199,6 +200,7 @@ sub new { push @exclude, @config_exclude; push @exclude_watch, @config_exclude_watch; + my @precious = @{$config->{precious} || []}; my $outdir = abs2rel($self->{outdir}, $self->{srcdir}); if ($outdir !~ m{^\.\./}) { @@ -214,6 +216,10 @@ sub new { \@exclude_watch, ignoreCase => !$self->{'case-sensitive'} ); + $self->{__q_precious} = File::Globstar::ListMatch->new( + \@precious, + ignoreCase => !$self->{'case-sensitive'} + ); $self->{defaults} = $self->__compileDefaults($self->{defaults}); } diff --git a/lib/Qgoda/Schema.pm b/lib/Qgoda/Schema.pm index e2d46b1..4eb4610 100644 --- a/lib/Qgoda/Schema.pm +++ b/lib/Qgoda/Schema.pm @@ -358,6 +358,15 @@ sub config { } } }, + precious => { + description => __"List of file name patterns that should not" + . "be deleted in the output directory.", + type => 'array', + items => { + type => 'string' + }, + default => [] + }, private => { description => __"Site-specific variables. You can also choose" . " the namespace 'site' if you prefer.", diff --git a/t/config-default.t b/t/config-default.t index 0749742..8cb5e87 100644 --- a/t/config-default.t +++ b/t/config-default.t @@ -82,6 +82,7 @@ po: post-processors: modules: [] options: {} +precious: [] processors: chains: html: