From 33fb63a0b2fd15e315e255e86c29feac0336aaa3 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Tue, 12 Sep 2023 17:22:54 +0100 Subject: [PATCH 1/5] Add config flag to indicate SSG is running --- src/Commands/StaticSiteGenerate.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Commands/StaticSiteGenerate.php b/src/Commands/StaticSiteGenerate.php index 0660f00..8bf823a 100644 --- a/src/Commands/StaticSiteGenerate.php +++ b/src/Commands/StaticSiteGenerate.php @@ -55,6 +55,8 @@ public function handle() { Partyline::bind($this); + config(['statamic.ssg.running' => true]); + if (config('statamic.editions.pro') && ! config('statamic.system.license_key')) { $this->error('Statamic Pro is enabled but no site license was found.'); $this->warn('Please set a valid Statamic License Key in your .env file.'); From 04ae1f6529817fa9154b263fef5d83d54b9596aa Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Tue, 12 Sep 2023 17:28:14 +0100 Subject: [PATCH 2/5] Add assertion --- tests/Concerns/RunsGeneratorCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Concerns/RunsGeneratorCommand.php b/tests/Concerns/RunsGeneratorCommand.php index 1b12e7c..87c3236 100644 --- a/tests/Concerns/RunsGeneratorCommand.php +++ b/tests/Concerns/RunsGeneratorCommand.php @@ -33,6 +33,8 @@ protected function generate($options = []) ->doesntExpectOutputToContain('pages not generated'); $this->assertTrue($this->files->exists($this->destination)); + + $this->assertTrue(app('config')->get('statamic.ssg.running')); return $this->getGeneratedFilesAtPath($this->destination); } From a66258204b19e5f290265c2933dcb1ce9549e88a Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Tue, 12 Sep 2023 17:30:47 +0100 Subject: [PATCH 3/5] Migrate PHPUnit XML schema --- phpunit.xml | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index bfc27ff..2adcc5a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,24 +1,16 @@ - - - - ./tests - - - - - - - - - - + + + + ./tests + + + + + + + + + + From 593fbc4ea7cde3653700eb32b70e74140e9adda2 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Tue, 12 Sep 2023 17:37:41 +0100 Subject: [PATCH 4/5] Add readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 4ca2d9b..e9b3334 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,17 @@ You may configure a custom routing style in `config/statamic/ssg.php`: 'pagination_route' => '{url}/{page_name}/{page_number}', ``` +## Views + +You can tell if the SSG was running from your templates by using the following check. + +This is antlers, but the same principle will work for any conditional checking the `statamic.ssg.running` config key: + +``` +{{ if ! config:statamic:ssg:running }} + +{{ /if }} +``` ## Post-generation callback From a2eab4ff18f0d376277e353c1b6768668f467824 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Tue, 12 Sep 2023 18:33:08 +0100 Subject: [PATCH 5/5] Code style --- tests/Concerns/RunsGeneratorCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Concerns/RunsGeneratorCommand.php b/tests/Concerns/RunsGeneratorCommand.php index 87c3236..a5deec3 100644 --- a/tests/Concerns/RunsGeneratorCommand.php +++ b/tests/Concerns/RunsGeneratorCommand.php @@ -33,7 +33,7 @@ protected function generate($options = []) ->doesntExpectOutputToContain('pages not generated'); $this->assertTrue($this->files->exists($this->destination)); - + $this->assertTrue(app('config')->get('statamic.ssg.running')); return $this->getGeneratedFilesAtPath($this->destination);