Skip to content

Commit

Permalink
Support for mounts points in static configuration (#2103)
Browse files Browse the repository at this point in the history
Support for mounts points in static configuration.

Co-authored-by: Arnaud Ligny <[email protected]>
  • Loading branch information
Progi1984 and ArnaudLigny authored Feb 3, 2025
1 parent 517ba00 commit bb9ce0d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docs/4-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 21 additions & 1 deletion src/Step/StaticFiles/Copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/website/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
'path',
],
'load' => true,
'mounts' => [
'ISS.jpg' => 'mount_test/iss.jpg', // file
'video' => 'mount_test', // directory
],
],
'assets' => [
'compile' => [
Expand Down

0 comments on commit bb9ce0d

Please sign in to comment.