Skip to content

Commit

Permalink
Merge pull request #140 from gflohr/precious-files
Browse files Browse the repository at this point in the history
support precious files
  • Loading branch information
gflohr authored Jan 26, 2024
2 parents 33a319b + 7b5dcec commit 9a70da8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/Qgoda.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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, '';
Expand Down
8 changes: 7 additions & 1 deletion lib/Qgoda/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}]
Expand Down Expand Up @@ -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{^\.\./}) {
Expand All @@ -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});
}
Expand Down
9 changes: 9 additions & 0 deletions lib/Qgoda/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions t/config-default.t
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ po:
post-processors:
modules: []
options: {}
precious: []
processors:
chains:
html:
Expand Down

0 comments on commit 9a70da8

Please sign in to comment.