diff --git a/docs/4-Configuration.md b/docs/4-Configuration.md index fdf678f61..bed4ec84b 100644 --- a/docs/4-Configuration.md +++ b/docs/4-Configuration.md @@ -833,6 +833,7 @@ static: target: '' # target directory exclude: ['sass', 'scss', '*.scss', 'package*.json', 'node_modules'] # list of excluded files (accepts globs, strings and regexes) load: false # enables `site.static` collection (`false` by default) + mounts: [] # allows to copy specific files or directories to a specific destination ``` :::important @@ -848,6 +849,20 @@ exclude: ['sass', 'scss', '*.scss', 'package*.json', '#node_modules/(?!bootstrap ::: +:::info +You can copy some files from `static/` directory to a specific destination with the `mounts` option. + +Examples: + +```yaml +mounts: + - source/path/file.ext: destination/path/file.ext + - source/path: destination/path + - node_modules/bootstrap-icons/font/fonts: fonts +``` + +::: + _Example:_ ```yaml diff --git a/src/Step/StaticFiles/Copy.php b/src/Step/StaticFiles/Copy.php index 9242e2a05..ba291e811 100644 --- a/src/Step/StaticFiles/Copy.php +++ b/src/Step/StaticFiles/Copy.php @@ -69,6 +69,13 @@ public function process(): void } } + // copying mounts + if ($this->config->get('static.mounts')) { + foreach ($this->config->get('static.mounts') as $source => $destination) { + $this->copy(Util::joinFile($this->config->getStaticPath(), (string) $source), (string) $destination); + } + } + // copying content of 'static/' dir if exists $this->copy($this->config->getStaticPath(), $target, $exclude); @@ -98,15 +105,28 @@ public function process(): void } /** - * Copying (mirror) files. + * Copying a file or files in a directory from $from to $to (relative to output path). + * Exclude files or directories with $exclude array. */ protected function copy(string $from, ?string $to = null, ?array $exclude = null): bool { if (Util\File::getFS()->exists($from)) { + // copy a file + if (is_file($from)) { + Util\File::getFS()->copy( + $from, + Util::joinFile($this->config->getOutputPath(), $to ?? ''), + true + ); + + return true; + } + // copy a directory $finder = Finder::create() ->files() ->in($from) ->ignoreDotFiles(false); + // exclude files or directories if (\is_array($exclude)) { $finder->notPath($exclude); $finder->notName($exclude); diff --git a/tests/fixtures/website/config.php b/tests/fixtures/website/config.php index 4a7d563aa..d89136d20 100644 --- a/tests/fixtures/website/config.php +++ b/tests/fixtures/website/config.php @@ -176,6 +176,10 @@ 'path', ], 'load' => true, + 'mounts' => [ + 'ISS.jpg' => 'mount_test/iss.jpg', // file + 'video' => 'mount_test', // directory + ], ], 'assets' => [ 'compile' => [