Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support precious files #140

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading