From ead8bfa1b77333dc0e137b6396d8e91066bd4ebf Mon Sep 17 00:00:00 2001 From: Daniel Shields Date: Thu, 10 Dec 2020 02:09:22 +0200 Subject: [PATCH] Allow wildcards in excludes (#25) --- README.md | 10 +++++++++- src/Generator.php | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb7aee7..de34a49 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Install the package using Composer: composer require statamic/ssg ``` -If you want or need to customize the way the site is generated, you can do so by publishing and modifying the config file with the following command: +If you want or need to customize the way the site is generated, you can do so by publishing and modifying the config file with the following command: ``` php artisan vendor:publish --provider="Statamic\StaticSite\ServiceProvider" @@ -50,6 +50,14 @@ Routes will not automatically be generated. You can add any additional URLs you ], ``` +You can also exclude single routes, or route groups with wildcards. This will override anything in the `urls` config. + +``` php +'exclude' => [ + '/secret-page', + '/cheat-codes/*', +], +``` ## Post-generation callback diff --git a/src/Generator.php b/src/Generator.php index ea47ec0..acbd944 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -176,6 +176,12 @@ protected function pages() ->merge($this->scopedTerms()) ->values() ->reject(function ($page) { + foreach ($this->config['exclude'] as $url) { + if (Str::endsWith($url, '*')) { + if (Str::is($url, $page->url())) return true; + } + } + return in_array($page->url(), $this->config['exclude']); })->sortBy(function ($page) { return str_replace('/', '', $page->url());