From 94abaa76ff584328ade2e447e986f05b1438dfb6 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 16 May 2022 09:46:47 +0000 Subject: [PATCH 01/27] Apply fixes from StyleCI [ci skip] [skip ci] --- tests/Unit/HydeBasePathCanBeChangedTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Unit/HydeBasePathCanBeChangedTest.php b/tests/Unit/HydeBasePathCanBeChangedTest.php index 2a2871bd..c3611b07 100644 --- a/tests/Unit/HydeBasePathCanBeChangedTest.php +++ b/tests/Unit/HydeBasePathCanBeChangedTest.php @@ -20,8 +20,7 @@ protected function setUp(): void { parent::setUp(); - if (! isset($this->basePath)) - { + if (! isset($this->basePath)) { $this->basePath = Hyde::getBasePath(); } } @@ -29,7 +28,7 @@ protected function setUp(): void protected function tearDown(): void { Hyde::setBasePath($this->basePath); - + parent::tearDown(); } From a423dc179207870162a7eb8822840864a5f15f83 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 11:54:49 +0200 Subject: [PATCH 02/27] Rename SourcePathHelpers to FluentPathHelpers --- .../{SourcePathHelpers.php => FluentPathHelpers.php} | 4 ++-- src/Hyde.php | 4 ++-- ...{SourcePathHelpersTest.php => FluentPathHelpersTest.php} | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) rename src/Concerns/Internal/{SourcePathHelpers.php => FluentPathHelpers.php} (96%) rename tests/Unit/{SourcePathHelpersTest.php => FluentPathHelpersTest.php} (94%) diff --git a/src/Concerns/Internal/SourcePathHelpers.php b/src/Concerns/Internal/FluentPathHelpers.php similarity index 96% rename from src/Concerns/Internal/SourcePathHelpers.php rename to src/Concerns/Internal/FluentPathHelpers.php index 31e21567..e6358771 100644 --- a/src/Concerns/Internal/SourcePathHelpers.php +++ b/src/Concerns/Internal/FluentPathHelpers.php @@ -18,9 +18,9 @@ * Hyde::path('_pages/foo') becomes Hyde::getBladePagePath('foo') * * @see \Hyde\Framework\Hyde - * @see \Tests\Unit\SourcePathHelpersTest + * @see \Tests\Unit\FluentPathHelpersTest */ -trait SourcePathHelpers +trait FluentPathHelpers { public static function getBladePagePath(string $path = ''): string { diff --git a/src/Hyde.php b/src/Hyde.php index c3cb71a7..faca7c2c 100644 --- a/src/Hyde.php +++ b/src/Hyde.php @@ -5,7 +5,7 @@ use Composer\InstalledVersions; use Hyde\Framework\Concerns\Internal\AssetManager; use Hyde\Framework\Concerns\Internal\FileHelpers; -use Hyde\Framework\Concerns\Internal\SourcePathHelpers; +use Hyde\Framework\Concerns\Internal\FluentPathHelpers; use Hyde\Framework\Services\CollectionService; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -23,7 +23,7 @@ class Hyde { use FileHelpers; use AssetManager; - use SourcePathHelpers; + use FluentPathHelpers; protected static string $basePath; diff --git a/tests/Unit/SourcePathHelpersTest.php b/tests/Unit/FluentPathHelpersTest.php similarity index 94% rename from tests/Unit/SourcePathHelpersTest.php rename to tests/Unit/FluentPathHelpersTest.php index 4867b7cd..230ed73a 100644 --- a/tests/Unit/SourcePathHelpersTest.php +++ b/tests/Unit/FluentPathHelpersTest.php @@ -10,11 +10,11 @@ use Tests\TestCase; /** - * Class SourcePathHelpersTest. + * Class FluentPathHelpersTest. * - * @covers \Hyde\Framework\Concerns\Internal\SourcePathHelpers + * @covers \Hyde\Framework\Concerns\Internal\FluentPathHelpers */ -class SourcePathHelpersTest extends TestCase +class FluentPathHelpersTest extends TestCase { public function test_get_model_source_path_method_returns_path_for_model_classes() { From 003ed04dec01b1341cbe06567515aeefeeeb11c4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 12:19:18 +0200 Subject: [PATCH 03/27] Add StaticPageBuilder::$outputPath property --- src/StaticPageBuilder.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/StaticPageBuilder.php b/src/StaticPageBuilder.php index 69a9e0a4..63ae6d9a 100644 --- a/src/StaticPageBuilder.php +++ b/src/StaticPageBuilder.php @@ -17,6 +17,11 @@ */ class StaticPageBuilder { + /** + * @var string Absolute path to the directory to place compiled files in. + */ + public static string $outputPath; + /** * Construct the class. * From c24237621ae39eb29ef32292990116025bc25028 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 12:19:28 +0200 Subject: [PATCH 04/27] Register the output path --- src/HydeServiceProvider.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/HydeServiceProvider.php b/src/HydeServiceProvider.php index 3c1e1027..1654664a 100644 --- a/src/HydeServiceProvider.php +++ b/src/HydeServiceProvider.php @@ -54,6 +54,8 @@ function () { $this->discoverBladeViewsIn('_pages'); + $this->storeCompiledSiteIn('_site'); + $this->commands([ Commands\HydePublishHomepageCommand::class, Commands\HydeUpdateConfigsCommand::class, @@ -111,4 +113,13 @@ protected function discoverBladeViewsIn(string $directory): void [base_path($directory)] )]); } + + /** + * The path to the directory when the compiled site is stored. + * Expects a relative path parameter and sets an absolute path. + */ + protected function storeCompiledSiteIn(string $directory): void + { + StaticPageBuilder::$outputPath = Hyde::path($directory); + } } From 55f1f41e6c6a1f4b1611660af7101ee37be1dce6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 12:19:54 +0200 Subject: [PATCH 05/27] Add Hyde::getSiteOutputPath() helper --- src/Concerns/Internal/FluentPathHelpers.php | 12 ++++++++++++ tests/Unit/FluentPathHelpersTest.php | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Concerns/Internal/FluentPathHelpers.php b/src/Concerns/Internal/FluentPathHelpers.php index e6358771..1e3303f4 100644 --- a/src/Concerns/Internal/FluentPathHelpers.php +++ b/src/Concerns/Internal/FluentPathHelpers.php @@ -7,6 +7,7 @@ use Hyde\Framework\Models\MarkdownPage; use Hyde\Framework\Models\MarkdownPost; use Hyde\Framework\Services\DiscoveryService; +use Hyde\Framework\StaticPageBuilder; /** * Offloads file helper methods for the Hyde Facade. @@ -52,4 +53,15 @@ public static function getModelSourcePath(string $model, string $path = ''): str return static::path(DiscoveryService::getFilePathForModelClassFiles($model).DIRECTORY_SEPARATOR.$path); } + + public static function getSiteOutputPath(string $path = ''): string + { + if (empty($path)) { + return StaticPageBuilder::$outputPath; + } + + $path = trim($path, '/\\'); + + return StaticPageBuilder::$outputPath.DIRECTORY_SEPARATOR.$path; + } } diff --git a/tests/Unit/FluentPathHelpersTest.php b/tests/Unit/FluentPathHelpersTest.php index 230ed73a..f7e9bae9 100644 --- a/tests/Unit/FluentPathHelpersTest.php +++ b/tests/Unit/FluentPathHelpersTest.php @@ -93,4 +93,20 @@ public function test_helper_for_documentation_pages() Hyde::getDocumentationPagePath() ); } + + public function test_helper_for_site_output_path() + { + $this->assertEquals( + Hyde::path('_site'), + Hyde::getSiteOutputPath() + ); + } + + public function test_helper_for_site_output_path_returns_path_to_file_within_the_directory() + { + $this->assertEquals( + Hyde::path('_site'.DIRECTORY_SEPARATOR.'foo.html'), + Hyde::getSiteOutputPath('foo.html') + ); + } } From 7fc4534d6b8bbff47a1de6744d6c2f38a7c1973f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 12:20:09 +0200 Subject: [PATCH 06/27] Change order of methods --- src/Concerns/Internal/FluentPathHelpers.php | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Concerns/Internal/FluentPathHelpers.php b/src/Concerns/Internal/FluentPathHelpers.php index 1e3303f4..180f15ac 100644 --- a/src/Concerns/Internal/FluentPathHelpers.php +++ b/src/Concerns/Internal/FluentPathHelpers.php @@ -23,6 +23,17 @@ */ trait FluentPathHelpers { + public static function getModelSourcePath(string $model, string $path = ''): string + { + if (empty($path)) { + return static::path(DiscoveryService::getFilePathForModelClassFiles($model)); + } + + $path = trim($path, '/\\'); + + return static::path(DiscoveryService::getFilePathForModelClassFiles($model).DIRECTORY_SEPARATOR.$path); + } + public static function getBladePagePath(string $path = ''): string { return static::getModelSourcePath(BladePage::class, $path); @@ -43,17 +54,6 @@ public static function getDocumentationPagePath(string $path = ''): string return static::getModelSourcePath(DocumentationPage::class, $path); } - public static function getModelSourcePath(string $model, string $path = ''): string - { - if (empty($path)) { - return static::path(DiscoveryService::getFilePathForModelClassFiles($model)); - } - - $path = trim($path, '/\\'); - - return static::path(DiscoveryService::getFilePathForModelClassFiles($model).DIRECTORY_SEPARATOR.$path); - } - public static function getSiteOutputPath(string $path = ''): string { if (empty($path)) { From b43ab7a766a915712703c5f6adfad681407f9067 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 12:30:35 +0200 Subject: [PATCH 07/27] Add @todo Refactor to work with custom paths. --- src/Commands/HydeRebuildStaticSiteCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Commands/HydeRebuildStaticSiteCommand.php b/src/Commands/HydeRebuildStaticSiteCommand.php index de4edde0..4c9edaa1 100644 --- a/src/Commands/HydeRebuildStaticSiteCommand.php +++ b/src/Commands/HydeRebuildStaticSiteCommand.php @@ -11,6 +11,7 @@ /** * Hyde Command to build a single static site file. + * @todo Refactor to work with custom paths. */ class HydeRebuildStaticSiteCommand extends Command { @@ -92,7 +93,7 @@ public function sanitizePathString(string $path): string /** * Validate the path to catch common errors. - * + * * @throws Exception */ public function validate(): void From 283bdd62c9ff69f183652738d08d84c9166d981a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:07:14 +0200 Subject: [PATCH 08/27] Create helper concern to create the required directories --- src/Concerns/InteractsWithDirectories.php | 31 +++++++++ .../InteractsWithDirectoriesConcernTest.php | 64 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/Concerns/InteractsWithDirectories.php create mode 100644 tests/Unit/InteractsWithDirectoriesConcernTest.php diff --git a/src/Concerns/InteractsWithDirectories.php b/src/Concerns/InteractsWithDirectories.php new file mode 100644 index 00000000..8dded380 --- /dev/null +++ b/src/Concerns/InteractsWithDirectories.php @@ -0,0 +1,31 @@ +needsDirectory($directory); + } + } +} \ No newline at end of file diff --git a/tests/Unit/InteractsWithDirectoriesConcernTest.php b/tests/Unit/InteractsWithDirectoriesConcernTest.php new file mode 100644 index 00000000..7de79480 --- /dev/null +++ b/tests/Unit/InteractsWithDirectoriesConcernTest.php @@ -0,0 +1,64 @@ +needsDirectory(Hyde::path('foo')); + $this->assertDirectoryExists(Hyde::path('foo')); + } + + public function test_needs_directory_creates_the_directory_recursively() + { + $this->needsDirectory(Hyde::path('foo/bar/baz')); + $this->assertDirectoryExists(Hyde::path('foo/bar/baz')); + } + + public function test_needs_directory_handles_existing_directory() + { + $this->needsDirectory(Hyde::path('foo')); + $this->needsDirectory(Hyde::path('foo')); + $this->assertDirectoryExists(Hyde::path('foo')); + } + + public function test_needs_directories_creates_single_directory() + { + $this->needsDirectories([Hyde::path('foo')]); + $this->assertDirectoryExists(Hyde::path('foo')); + } + + public function test_needs_directories_creates_multiple_directories() + { + $this->needsDirectories([Hyde::path('foo'), Hyde::path('bar')]); + $this->assertDirectoryExists(Hyde::path('foo')); + $this->assertDirectoryExists(Hyde::path('bar')); + } +} From 0de9d3600e442db527f6f8f5ac4f0ebe951f9650 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:09:17 +0200 Subject: [PATCH 09/27] Deprecate docsDirectory pending config rename --- src/Concerns/Internal/FileHelpers.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Concerns/Internal/FileHelpers.php b/src/Concerns/Internal/FileHelpers.php index 1bdc021c..7f80083b 100644 --- a/src/Concerns/Internal/FileHelpers.php +++ b/src/Concerns/Internal/FileHelpers.php @@ -14,7 +14,9 @@ trait FileHelpers { /** * Get the subdirectory compiled documentation files are stored in. - * + * @deprecated will be renamed to be more distinct from other path helpers. + * Naming suggestion is `getDocumentationOutputPath()`. + * The configuration is deprecated as well and will be renamed. * @return string */ public static function docsDirectory(): string From 4d545862934aa9d4b8524588efa38c285a9b248b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:10:52 +0200 Subject: [PATCH 10/27] Create the needed directories when they are needed --- src/StaticPageBuilder.php | 18 ++++---- .../BuildOutputDirectoryCanBeChangedTest.php | 42 +++++++++++++++++++ 2 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 tests/Feature/BuildOutputDirectoryCanBeChangedTest.php diff --git a/src/StaticPageBuilder.php b/src/StaticPageBuilder.php index 63ae6d9a..9f253ba0 100644 --- a/src/StaticPageBuilder.php +++ b/src/StaticPageBuilder.php @@ -8,15 +8,15 @@ use Hyde\Framework\Models\MarkdownDocument; use Hyde\Framework\Models\MarkdownPage; use Hyde\Framework\Models\MarkdownPost; +use Hyde\Framework\Concerns\InteractsWithDirectories; /** * Converts a Page Model into a static HTML page. - * - * @todo Create the required directories if they don't exist. - * Can be done using a trait where an array of the required directories is passed. */ class StaticPageBuilder { + use InteractsWithDirectories; + /** * @var string Absolute path to the directory to place compiled files in. */ @@ -33,6 +33,8 @@ public function __construct(protected MarkdownDocument|BladePage $page, bool $se if ($selfInvoke) { $this->__invoke(); } + + $this->needsDirectory(static::$outputPath); } /** @@ -47,6 +49,7 @@ public function __invoke() } if ($this->page instanceof MarkdownPost) { + $this->needsDirectory(Hyde::getSiteOutputPath('posts')); return $this->save('posts/'.$this->page->slug, $this->compilePost()); } @@ -55,7 +58,8 @@ public function __invoke() } if ($this->page instanceof DocumentationPage) { - $this->makeSureDocsDirectoryExists(); + $this->needsDirectory(Hyde::getSiteOutputPath(Hyde::docsDirectory())); + // $this->makeSureDocsDirectoryExists(); return $this->save(Hyde::docsDirectory().'/'.$this->page->slug, $this->compileDocs()); } @@ -64,12 +68,12 @@ public function __invoke() /** * Save the compiled HTML to file. * - * @param string $location of the output file relative to _site/ + * @param string $location of the output file relative to the site output directory * @param string $contents to save to the file */ private function save(string $location, string $contents): bool|int { - $path = Hyde::path("_site/$location.html"); + $path = Hyde::getSiteOutputPath("$location.html"); return file_put_contents($path, $contents); } @@ -133,7 +137,7 @@ private function compileDocs(): string /** * Make sure the config defined directory for outputting the * documentation files exists by creating it if it doesn't. - * + * @deprecated * @return void */ protected function makeSureDocsDirectoryExists(): void diff --git a/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php b/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php new file mode 100644 index 00000000..ed99a4db --- /dev/null +++ b/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php @@ -0,0 +1,42 @@ +execute(); + + $this->assertFileExists(Hyde::path('build/posts/test-post.html')); + + File::deleteDirectory(Hyde::path('build')); + unlink(Hyde::path('_posts/test-post.md')); + } + + public function test_output_directory_is_created_if_it_does_not_exist_in_static_page_builder() + { + createTestPost(); + File::deleteDirectory(Hyde::path('build/foo')); + StaticPageBuilder::$outputPath = Hyde::path('build/foo'); + (new RebuildService('_posts/test-post.md'))->execute(); + + $this->assertFileExists(Hyde::path('build/foo/posts/test-post.html')); + File::deleteDirectory(Hyde::path('build/foo')); + unlink(Hyde::path('_posts/test-post.md')); + } +} From feabaceb699f5a7204a1ef8a9da9e1ed9c0f8426 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:11:23 +0200 Subject: [PATCH 11/27] Remove deprecated makeSureDocsDirectoryExists() --- src/StaticPageBuilder.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/StaticPageBuilder.php b/src/StaticPageBuilder.php index 9f253ba0..61278875 100644 --- a/src/StaticPageBuilder.php +++ b/src/StaticPageBuilder.php @@ -59,7 +59,6 @@ public function __invoke() if ($this->page instanceof DocumentationPage) { $this->needsDirectory(Hyde::getSiteOutputPath(Hyde::docsDirectory())); - // $this->makeSureDocsDirectoryExists(); return $this->save(Hyde::docsDirectory().'/'.$this->page->slug, $this->compileDocs()); } @@ -133,17 +132,4 @@ private function compileDocs(): string 'currentPage' => Hyde::docsDirectory().'/'.$this->page->slug, ])->render(); } - - /** - * Make sure the config defined directory for outputting the - * documentation files exists by creating it if it doesn't. - * @deprecated - * @return void - */ - protected function makeSureDocsDirectoryExists(): void - { - if (! file_exists(Hyde::path('_site/'.Hyde::docsDirectory()))) { - mkdir(Hyde::path('_site/'.Hyde::docsDirectory()), recursive: true); - } - } } From e6f5ee20e905036450ae83a4599f18ac0b104221 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:20:48 +0200 Subject: [PATCH 12/27] Use the dynamic site output path helper --- src/Commands/HydeBuildStaticSiteCommand.php | 10 +++++----- .../Internal/TransfersMediaAssetsForBuildCommands.php | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index 8f8fb421..7b278eca 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -119,12 +119,12 @@ protected function printFinishMessage(float $time_start): void $this->info('Congratulations! ๐ŸŽ‰ Your static site has been built!'); $this->line( 'Your new homepage is stored here -> '. - DiscoveryService::createClickableFilepath(Hyde::path('_site/index.html')) + DiscoveryService::createClickableFilepath(Hyde::getSiteOutputPath('index.html')) ); } /** - * Clear the entire _site directory before running the build. + * Clear the entire output directory before running the build. * * @return void */ @@ -132,8 +132,8 @@ public function purge(): void { $this->warn('Removing all files from build directory.'); - File::deleteDirectory(Hyde::path('_site')); - mkdir(Hyde::path('_site')); + File::deleteDirectory(Hyde::getSiteOutputPath()); + mkdir(Hyde::getSiteOutputPath()); $this->line(' > Directory purged'); @@ -152,7 +152,7 @@ public function postBuildActions(): void { if ($this->option('pretty')) { $this->runNodeCommand( - 'npx prettier _site/ --write --bracket-same-line', + 'npx prettier '.basename(Hyde::getSiteOutputPath()).'/ --write --bracket-same-line', 'Prettifying code!', 'prettify code' ); diff --git a/src/Concerns/Internal/TransfersMediaAssetsForBuildCommands.php b/src/Concerns/Internal/TransfersMediaAssetsForBuildCommands.php index 8c280562..8446254b 100644 --- a/src/Concerns/Internal/TransfersMediaAssetsForBuildCommands.php +++ b/src/Concerns/Internal/TransfersMediaAssetsForBuildCommands.php @@ -4,6 +4,7 @@ use Hyde\Framework\Hyde; use Hyde\Framework\Services\CollectionService; +use Hyde\Framework\Concerns\InteractsWithDirectories; /** * Transfer all media assets to the build directory. @@ -16,16 +17,19 @@ trait TransfersMediaAssetsForBuildCommands { use BuildActionRunner; + use InteractsWithDirectories; /** @internal */ protected function transferMediaAssets(): void { + $this->needsDirectory(Hyde::getSiteOutputPath('media')); + $collection = CollectionService::getMediaAssetFiles(); if ($this->canRunBuildAction($collection, 'Media Assets', 'Transferring')) { $this->withProgressBar( $collection, function ($filepath) { - copy($filepath, Hyde::path('_site/media/'.basename($filepath))); + copy($filepath, Hyde::getSiteOutputPath('media/'.basename($filepath))); } ); $this->newLine(2); From d949f9279f3aae4787e5d284802550794b9a8418 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:22:02 +0200 Subject: [PATCH 13/27] Add todo #361 --- src/Commands/HydeBuildStaticSiteCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index 7b278eca..1cd4446a 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -21,6 +21,7 @@ * Hyde Command to run the Build Process. * * @see \Tests\Feature\Commands\BuildStaticSiteCommandTest + * @todo #361 Rename --pretty option to --run-prettier to distinguish it better */ class HydeBuildStaticSiteCommand extends Command { From 2671f68e27a896b723411048c20148e4aa1d15af Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:35:25 +0200 Subject: [PATCH 14/27] Add helper to get the relative site output path --- src/Concerns/Internal/FluentPathHelpers.php | 13 ++++++++ tests/Unit/FluentPathHelpersTest.php | 37 +++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/Concerns/Internal/FluentPathHelpers.php b/src/Concerns/Internal/FluentPathHelpers.php index 180f15ac..b73039f4 100644 --- a/src/Concerns/Internal/FluentPathHelpers.php +++ b/src/Concerns/Internal/FluentPathHelpers.php @@ -54,6 +54,9 @@ public static function getDocumentationPagePath(string $path = ''): string return static::getModelSourcePath(DocumentationPage::class, $path); } + /** + * Get the absolute path to the compiled site directory, or a file within it. + */ public static function getSiteOutputPath(string $path = ''): string { if (empty($path)) { @@ -64,4 +67,14 @@ public static function getSiteOutputPath(string $path = ''): string return StaticPageBuilder::$outputPath.DIRECTORY_SEPARATOR.$path; } + + /** + * Get the relative path to the compiled site directory, or a file within it. + */ + public static function getRelativeSiteOutputPath(string $path = ''): string + { + return trim(str_replace( + static::path(), '', static::getSiteOutputPath($path)), '/\\' + ); + } } diff --git a/tests/Unit/FluentPathHelpersTest.php b/tests/Unit/FluentPathHelpersTest.php index f7e9bae9..547903ed 100644 --- a/tests/Unit/FluentPathHelpersTest.php +++ b/tests/Unit/FluentPathHelpersTest.php @@ -109,4 +109,41 @@ public function test_helper_for_site_output_path_returns_path_to_file_within_the Hyde::getSiteOutputPath('foo.html') ); } + + public function test_get_site_output_path_returns_absolute_path() + { + $this->assertEquals( + Hyde::path('_site'), + Hyde::getSiteOutputPath() + ); + } + + public function test_get_relative_site_output_path_returns_relative_path() + { + $this->assertEquals( + '_site', + Hyde::getRelativeSiteOutputPath() + ); + } + + public function test_get_relative_site_output_path_returns_relative_path_to_file() + { + $this->assertEquals( + '_site'.DIRECTORY_SEPARATOR.'foo.html', + Hyde::getRelativeSiteOutputPath('foo.html') + ); + } + + public function test_site_output_path_helpers_ignore_trailing_slashes() + { + $this->assertEquals( + Hyde::path('_site'.DIRECTORY_SEPARATOR.'foo.html'), + Hyde::getSiteOutputPath('/foo.html/') + ); + + $this->assertEquals( + '_site'.DIRECTORY_SEPARATOR.'foo.html', + Hyde::getRelativeSiteOutputPath('/foo.html/') + ); + } } From f22730dc0ba819e59a0dcdb4a72ad1d4379cdd83 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:38:00 +0200 Subject: [PATCH 15/27] Update phpdoc _site reference --- src/Concerns/Internal/FileHelpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Concerns/Internal/FileHelpers.php b/src/Concerns/Internal/FileHelpers.php index 7f80083b..9d4e95cb 100644 --- a/src/Concerns/Internal/FileHelpers.php +++ b/src/Concerns/Internal/FileHelpers.php @@ -103,7 +103,7 @@ public static function pageLink(string $destination): string * * @see \Tests\Unit\FileHelperRelativeLinkTest * - * @param string $destination relative to `_site` directory on compiled site + * @param string $destination relative to output directory on compiled site * @param string $current the current URI path relative to the same root * @return string */ From 1a48e8b0452361d3f2f7e667050dfe051c29f05a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:51:03 +0200 Subject: [PATCH 16/27] Add siteOutputPath config option --- config/hyde.php | 15 +++++++++++++++ src/HydeServiceProvider.php | 7 +++---- .../BuildOutputDirectoryCanBeChangedTest.php | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config/hyde.php b/config/hyde.php index 0b69a5f3..d27f1afd 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -224,6 +224,21 @@ 'docsDirectory' => 'docs', + /* + |-------------------------------------------------------------------------- + | Site Output Directory (Experimental ๐Ÿงช) + |-------------------------------------------------------------------------- + | + | If you want to store your compiled website in a different directory than + | the default `_pages`, you can change the path here. The Hyde::path() + | helper ensures the path is relative to your Hyde project. While + | you can set the path to an absolute path outside the project, + | this is not officially supported and may be unstable. + | + */ + + 'siteOutputPath' => Hyde\Framework\Hyde::path('_site'), + /* |-------------------------------------------------------------------------- | Documentation Sidebar Page Order diff --git a/src/HydeServiceProvider.php b/src/HydeServiceProvider.php index 1654664a..78a6273b 100644 --- a/src/HydeServiceProvider.php +++ b/src/HydeServiceProvider.php @@ -54,7 +54,7 @@ function () { $this->discoverBladeViewsIn('_pages'); - $this->storeCompiledSiteIn('_site'); + $this->storeCompiledSiteIn(config('hyde.siteOutputPath', Hyde::path('_site'))); $this->commands([ Commands\HydePublishHomepageCommand::class, @@ -115,11 +115,10 @@ protected function discoverBladeViewsIn(string $directory): void } /** - * The path to the directory when the compiled site is stored. - * Expects a relative path parameter and sets an absolute path. + * The absolute path to the directory when the compiled site is stored. */ protected function storeCompiledSiteIn(string $directory): void { - StaticPageBuilder::$outputPath = Hyde::path($directory); + StaticPageBuilder::$outputPath = $directory; } } diff --git a/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php b/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php index ed99a4db..d6369083 100644 --- a/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php +++ b/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php @@ -11,6 +11,7 @@ /** * Class BuildOutputDirectoryCanBeChangedTest. * @todo add test for the Rebuild Service + * @todo add test for configurable option */ class BuildOutputDirectoryCanBeChangedTest extends TestCase { From 5c819f5688e9b4d15537d4242dc708bc30832266 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:52:45 +0200 Subject: [PATCH 17/27] Update annotations for docsDirectory config/helper --- config/hyde.php | 3 +++ src/Concerns/Internal/FileHelpers.php | 1 + 2 files changed, 4 insertions(+) diff --git a/config/hyde.php b/config/hyde.php index d27f1afd..c6ec5587 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -222,6 +222,9 @@ | */ + /** + * @deprecated version 0.25.0, will be renamed to documentationOutputPath + */ 'docsDirectory' => 'docs', /* diff --git a/src/Concerns/Internal/FileHelpers.php b/src/Concerns/Internal/FileHelpers.php index 9d4e95cb..ddc517bd 100644 --- a/src/Concerns/Internal/FileHelpers.php +++ b/src/Concerns/Internal/FileHelpers.php @@ -17,6 +17,7 @@ trait FileHelpers * @deprecated will be renamed to be more distinct from other path helpers. * Naming suggestion is `getDocumentationOutputPath()`. * The configuration is deprecated as well and will be renamed. + * @todo Test and if needed add support for storing documentation files in the site root * @return string */ public static function docsDirectory(): string From aca438dffe4aa864d12312693b582bd3188cdec8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:54:39 +0200 Subject: [PATCH 18/27] Use getRelativeSiteOutputPath in NPM call to support nested directories --- src/Commands/HydeBuildStaticSiteCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index 1cd4446a..cd79e343 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -153,7 +153,7 @@ public function postBuildActions(): void { if ($this->option('pretty')) { $this->runNodeCommand( - 'npx prettier '.basename(Hyde::getSiteOutputPath()).'/ --write --bracket-same-line', + 'npx prettier '.Hyde::getRelativeSiteOutputPath().'/ --write --bracket-same-line', 'Prettifying code!', 'prettify code' ); From ef444b899005eb5d3ad5377341f23883119c98d4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 13:55:58 +0200 Subject: [PATCH 19/27] Add todo #363 --- src/Commands/HydeBuildStaticSiteCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index cd79e343..2a01262a 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -146,7 +146,7 @@ public function purge(): void /** * Run any post-build actions. - * + * @todo #363 Add unit test for prettier command (can work by comparing compiled baseline to output to see if it was prettified); * @return void */ public function postBuildActions(): void From 627b4e66718ab06678530671f7ca71b4f4479998 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 16 May 2022 11:56:08 +0000 Subject: [PATCH 20/27] Apply fixes from StyleCI --- src/Commands/HydeBuildStaticSiteCommand.php | 3 ++ src/Commands/HydeRebuildStaticSiteCommand.php | 3 +- src/Concerns/InteractsWithDirectories.php | 44 ++++++++++--------- src/Concerns/Internal/FileHelpers.php | 3 ++ src/Concerns/Internal/FluentPathHelpers.php | 2 +- .../TransfersMediaAssetsForBuildCommands.php | 2 +- src/StaticPageBuilder.php | 3 +- .../BuildOutputDirectoryCanBeChangedTest.php | 7 +-- .../InteractsWithDirectoriesConcernTest.php | 6 +-- 9 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index 2a01262a..f13ef4c5 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -21,6 +21,7 @@ * Hyde Command to run the Build Process. * * @see \Tests\Feature\Commands\BuildStaticSiteCommandTest + * * @todo #361 Rename --pretty option to --run-prettier to distinguish it better */ class HydeBuildStaticSiteCommand extends Command @@ -146,7 +147,9 @@ public function purge(): void /** * Run any post-build actions. + * * @todo #363 Add unit test for prettier command (can work by comparing compiled baseline to output to see if it was prettified); + * * @return void */ public function postBuildActions(): void diff --git a/src/Commands/HydeRebuildStaticSiteCommand.php b/src/Commands/HydeRebuildStaticSiteCommand.php index 4c9edaa1..6d62aa13 100644 --- a/src/Commands/HydeRebuildStaticSiteCommand.php +++ b/src/Commands/HydeRebuildStaticSiteCommand.php @@ -11,6 +11,7 @@ /** * Hyde Command to build a single static site file. + * * @todo Refactor to work with custom paths. */ class HydeRebuildStaticSiteCommand extends Command @@ -93,7 +94,7 @@ public function sanitizePathString(string $path): string /** * Validate the path to catch common errors. - * + * * @throws Exception */ public function validate(): void diff --git a/src/Concerns/InteractsWithDirectories.php b/src/Concerns/InteractsWithDirectories.php index 8dded380..3e6c5b41 100644 --- a/src/Concerns/InteractsWithDirectories.php +++ b/src/Concerns/InteractsWithDirectories.php @@ -7,25 +7,27 @@ */ trait InteractsWithDirectories { - /** - * Ensure the supplied directory exist by creating it if it does not. - * @param string $directory absolute file path to the directory - */ - public function needsDirectory(string $directory): void - { - if (! file_exists($directory)) { - mkdir($directory, recursive: true); - } - } + /** + * Ensure the supplied directory exist by creating it if it does not. + * + * @param string $directory absolute file path to the directory + */ + public function needsDirectory(string $directory): void + { + if (! file_exists($directory)) { + mkdir($directory, recursive: true); + } + } - /** - * Ensure the supplied directories exist by creating them if they don't. - * @param array $directories array with absolute file paths to the directories - */ - public function needsDirectories(array $directories): void - { - foreach ($directories as $directory) { - $this->needsDirectory($directory); - } - } -} \ No newline at end of file + /** + * Ensure the supplied directories exist by creating them if they don't. + * + * @param array $directories array with absolute file paths to the directories + */ + public function needsDirectories(array $directories): void + { + foreach ($directories as $directory) { + $this->needsDirectory($directory); + } + } +} diff --git a/src/Concerns/Internal/FileHelpers.php b/src/Concerns/Internal/FileHelpers.php index ddc517bd..27a25762 100644 --- a/src/Concerns/Internal/FileHelpers.php +++ b/src/Concerns/Internal/FileHelpers.php @@ -14,10 +14,13 @@ trait FileHelpers { /** * Get the subdirectory compiled documentation files are stored in. + * * @deprecated will be renamed to be more distinct from other path helpers. * Naming suggestion is `getDocumentationOutputPath()`. * The configuration is deprecated as well and will be renamed. + * * @todo Test and if needed add support for storing documentation files in the site root + * * @return string */ public static function docsDirectory(): string diff --git a/src/Concerns/Internal/FluentPathHelpers.php b/src/Concerns/Internal/FluentPathHelpers.php index b73039f4..24bb292a 100644 --- a/src/Concerns/Internal/FluentPathHelpers.php +++ b/src/Concerns/Internal/FluentPathHelpers.php @@ -33,7 +33,7 @@ public static function getModelSourcePath(string $model, string $path = ''): str return static::path(DiscoveryService::getFilePathForModelClassFiles($model).DIRECTORY_SEPARATOR.$path); } - + public static function getBladePagePath(string $path = ''): string { return static::getModelSourcePath(BladePage::class, $path); diff --git a/src/Concerns/Internal/TransfersMediaAssetsForBuildCommands.php b/src/Concerns/Internal/TransfersMediaAssetsForBuildCommands.php index 8446254b..73a323da 100644 --- a/src/Concerns/Internal/TransfersMediaAssetsForBuildCommands.php +++ b/src/Concerns/Internal/TransfersMediaAssetsForBuildCommands.php @@ -2,9 +2,9 @@ namespace Hyde\Framework\Concerns\Internal; +use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Framework\Hyde; use Hyde\Framework\Services\CollectionService; -use Hyde\Framework\Concerns\InteractsWithDirectories; /** * Transfer all media assets to the build directory. diff --git a/src/StaticPageBuilder.php b/src/StaticPageBuilder.php index 61278875..be1e5cff 100644 --- a/src/StaticPageBuilder.php +++ b/src/StaticPageBuilder.php @@ -3,12 +3,12 @@ namespace Hyde\Framework; use Hyde\Framework\Actions\MarkdownConverter; +use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Framework\Models\BladePage; use Hyde\Framework\Models\DocumentationPage; use Hyde\Framework\Models\MarkdownDocument; use Hyde\Framework\Models\MarkdownPage; use Hyde\Framework\Models\MarkdownPost; -use Hyde\Framework\Concerns\InteractsWithDirectories; /** * Converts a Page Model into a static HTML page. @@ -50,6 +50,7 @@ public function __invoke() if ($this->page instanceof MarkdownPost) { $this->needsDirectory(Hyde::getSiteOutputPath('posts')); + return $this->save('posts/'.$this->page->slug, $this->compilePost()); } diff --git a/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php b/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php index d6369083..47ebb7ac 100644 --- a/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php +++ b/tests/Feature/BuildOutputDirectoryCanBeChangedTest.php @@ -2,14 +2,15 @@ namespace Tests\Feature; -use Tests\TestCase; use Hyde\Framework\Hyde; -use Hyde\Framework\StaticPageBuilder; use Hyde\Framework\Services\RebuildService; +use Hyde\Framework\StaticPageBuilder; use Illuminate\Support\Facades\File; +use Tests\TestCase; /** * Class BuildOutputDirectoryCanBeChangedTest. + * * @todo add test for the Rebuild Service * @todo add test for configurable option */ @@ -18,7 +19,7 @@ class BuildOutputDirectoryCanBeChangedTest extends TestCase public function test_site_output_directory_can_be_changed_in_static_page_builder() { createTestPost(); - + StaticPageBuilder::$outputPath = Hyde::path('build'); (new RebuildService('_posts/test-post.md'))->execute(); diff --git a/tests/Unit/InteractsWithDirectoriesConcernTest.php b/tests/Unit/InteractsWithDirectoriesConcernTest.php index 7de79480..25182009 100644 --- a/tests/Unit/InteractsWithDirectoriesConcernTest.php +++ b/tests/Unit/InteractsWithDirectoriesConcernTest.php @@ -2,10 +2,10 @@ namespace Tests\Unit; +use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Framework\Hyde; use Illuminate\Support\Facades\File; use Tests\TestCase; -use Hyde\Framework\Concerns\InteractsWithDirectories; /** * Class InteractsWithDirectoriesConcernTest. @@ -32,8 +32,8 @@ protected function tearDown(): void public function test_needs_directory_creates_the_directory() { - $this->needsDirectory(Hyde::path('foo')); - $this->assertDirectoryExists(Hyde::path('foo')); + $this->needsDirectory(Hyde::path('foo')); + $this->assertDirectoryExists(Hyde::path('foo')); } public function test_needs_directory_creates_the_directory_recursively() From af9b3f7d13d129d7e67227ec840e55eada7476c6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 14:06:56 +0200 Subject: [PATCH 21/27] Wrap method call over new lines --- src/HydeServiceProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/HydeServiceProvider.php b/src/HydeServiceProvider.php index 78a6273b..85a7002b 100644 --- a/src/HydeServiceProvider.php +++ b/src/HydeServiceProvider.php @@ -54,7 +54,9 @@ function () { $this->discoverBladeViewsIn('_pages'); - $this->storeCompiledSiteIn(config('hyde.siteOutputPath', Hyde::path('_site'))); + $this->storeCompiledSiteIn(config( + 'hyde.siteOutputPath', Hyde::path('_site') + )); $this->commands([ Commands\HydePublishHomepageCommand::class, From 5badd48410a3f71ef81bd0b450fefb03bba907db Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 16:26:30 +0200 Subject: [PATCH 22/27] Create helper to decode absolute filepaths --- src/Concerns/Internal/FluentPathHelpers.php | 15 ++++-- tests/Unit/FluentPathHelpersTest.php | 51 ++++++++++++++++++++- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/Concerns/Internal/FluentPathHelpers.php b/src/Concerns/Internal/FluentPathHelpers.php index 24bb292a..0656890f 100644 --- a/src/Concerns/Internal/FluentPathHelpers.php +++ b/src/Concerns/Internal/FluentPathHelpers.php @@ -70,11 +70,20 @@ public static function getSiteOutputPath(string $path = ''): string /** * Get the relative path to the compiled site directory, or a file within it. + * @deprecated use Hyde::pathToRelative() instead */ public static function getRelativeSiteOutputPath(string $path = ''): string { - return trim(str_replace( - static::path(), '', static::getSiteOutputPath($path)), '/\\' - ); + return static::pathToRelative(static::getSiteOutputPath($path)); + } + + /** + * Decode an absolute path created with a Hyde::path() helper into its relative counterpart. + */ + public static function pathToRelative(string $path): string + { + return str_starts_with($path, static::path()) ? trim(str_replace( + static::path(), '', $path), '/\\' + ) : $path; } } diff --git a/tests/Unit/FluentPathHelpersTest.php b/tests/Unit/FluentPathHelpersTest.php index 547903ed..c55db8f3 100644 --- a/tests/Unit/FluentPathHelpersTest.php +++ b/tests/Unit/FluentPathHelpersTest.php @@ -11,7 +11,7 @@ /** * Class FluentPathHelpersTest. - * + * @deprecated Move to Feature namespace * @covers \Hyde\Framework\Concerns\Internal\FluentPathHelpers */ class FluentPathHelpersTest extends TestCase @@ -146,4 +146,53 @@ public function test_site_output_path_helpers_ignore_trailing_slashes() Hyde::getRelativeSiteOutputPath('/foo.html/') ); } + + public function test_path_to_relative_helper_decodes_hyde_path_into_relative() + { + $s = DIRECTORY_SEPARATOR; + $this->assertEquals('foo', Hyde::pathToRelative(Hyde::path('foo'))); + $this->assertEquals('foo', Hyde::pathToRelative(Hyde::path('/foo/'))); + $this->assertEquals('foo.md', Hyde::pathToRelative(Hyde::path('foo.md'))); + $this->assertEquals("foo{$s}bar", Hyde::pathToRelative(Hyde::path("foo{$s}bar"))); + $this->assertEquals("foo{$s}bar.md", Hyde::pathToRelative(Hyde::path("foo{$s}bar.md"))); + } + + public function test_path_to_relative_helper_does_not_modify_already_relative_paths() + { + $this->assertEquals('foo', Hyde::pathToRelative('foo')); + $this->assertEquals('foo/', Hyde::pathToRelative('foo/')); + $this->assertEquals('../foo', Hyde::pathToRelative('../foo')); + $this->assertEquals('../foo/', Hyde::pathToRelative('../foo/')); + $this->assertEquals('foo.md', Hyde::pathToRelative('foo.md')); + $this->assertEquals('foo/bar', Hyde::pathToRelative('foo/bar')); + $this->assertEquals('foo/bar.md', Hyde::pathToRelative('foo/bar.md')); + } + + public function test_path_to_relative_helper_does_not_modify_non_project_paths() + { + $testStrings = [ + 'C:\Documents\Newsletters\Summer2018.pdf', + '\Program Files\Custom Utilities\StringFinder.exe', + '2018\January.xlsx', + '..\Publications\TravelBrochure.pdf', + 'C:\Projects\library\library.sln', + 'C:Projects\library\library.sln', + '/home/seth/Pictures/penguin.jpg', + '~/Pictures/penguin.jpg', + ]; + + foreach ($testStrings as $testString) { + $this->assertEquals( + $this->systemPath(($testString)), + Hyde::pathToRelative( + $this->systemPath($testString) + ) + ); + } + } + + protected function systemPath(string $path): string + { + return str_replace('/', DIRECTORY_SEPARATOR, $path); + } } From fcb42dabe7ce6c612c0610b575742dd09c863b29 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 16:31:49 +0200 Subject: [PATCH 23/27] Refactor to work with custom paths --- src/Commands/HydeRebuildStaticSiteCommand.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Commands/HydeRebuildStaticSiteCommand.php b/src/Commands/HydeRebuildStaticSiteCommand.php index 6d62aa13..556abfdc 100644 --- a/src/Commands/HydeRebuildStaticSiteCommand.php +++ b/src/Commands/HydeRebuildStaticSiteCommand.php @@ -11,8 +11,6 @@ /** * Hyde Command to build a single static site file. - * - * @todo Refactor to work with custom paths. */ class HydeRebuildStaticSiteCommand extends Command { @@ -99,10 +97,11 @@ public function sanitizePathString(string $path): string */ public function validate(): void { - if (! (str_starts_with($this->path, '_docs') || - str_starts_with($this->path, '_posts') || - str_starts_with($this->path, '_pages') || - str_starts_with($this->path, '_pages') + if (! ( + str_starts_with($this->path, Hyde::pathToRelative(Hyde::getDocumentationPagePath())) || + str_starts_with($this->path, Hyde::pathToRelative(Hyde::getMarkdownPostPath())) || + str_starts_with($this->path, Hyde::pathToRelative(Hyde::getBladePagePath())) || + str_starts_with($this->path, Hyde::pathToRelative(Hyde::getMarkdownPostPath())) )) { throw new Exception("Path [$this->path] is not in a valid source directory.", 400); } @@ -128,6 +127,7 @@ public function handleException(Exception $exception): int /** * Get the output path for the given source file path. + * Will fall back to the input path when using non-standard source paths. * * @param string $path * @return string From 29dc0cf35251f87db83b2fa1d1829d50efcd4b21 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 16 May 2022 14:32:04 +0000 Subject: [PATCH 24/27] Apply fixes from StyleCI --- src/Concerns/Internal/FluentPathHelpers.php | 1 + tests/Unit/FluentPathHelpersTest.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Concerns/Internal/FluentPathHelpers.php b/src/Concerns/Internal/FluentPathHelpers.php index 0656890f..6a300413 100644 --- a/src/Concerns/Internal/FluentPathHelpers.php +++ b/src/Concerns/Internal/FluentPathHelpers.php @@ -70,6 +70,7 @@ public static function getSiteOutputPath(string $path = ''): string /** * Get the relative path to the compiled site directory, or a file within it. + * * @deprecated use Hyde::pathToRelative() instead */ public static function getRelativeSiteOutputPath(string $path = ''): string diff --git a/tests/Unit/FluentPathHelpersTest.php b/tests/Unit/FluentPathHelpersTest.php index c55db8f3..e68b85b3 100644 --- a/tests/Unit/FluentPathHelpersTest.php +++ b/tests/Unit/FluentPathHelpersTest.php @@ -11,6 +11,7 @@ /** * Class FluentPathHelpersTest. + * * @deprecated Move to Feature namespace * @covers \Hyde\Framework\Concerns\Internal\FluentPathHelpers */ @@ -183,7 +184,7 @@ public function test_path_to_relative_helper_does_not_modify_non_project_paths() foreach ($testStrings as $testString) { $this->assertEquals( - $this->systemPath(($testString)), + $this->systemPath(($testString)), Hyde::pathToRelative( $this->systemPath($testString) ) From 20d023b412a2b53f31dba93713045c273c35e670 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 16:41:18 +0200 Subject: [PATCH 25/27] Remove deprecated getRelativeSiteOutputPath --- src/Commands/HydeBuildStaticSiteCommand.php | 2 +- src/Concerns/Internal/FluentPathHelpers.php | 9 -------- tests/Unit/FluentPathHelpersTest.php | 23 +-------------------- 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index f13ef4c5..82848e4b 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -156,7 +156,7 @@ public function postBuildActions(): void { if ($this->option('pretty')) { $this->runNodeCommand( - 'npx prettier '.Hyde::getRelativeSiteOutputPath().'/ --write --bracket-same-line', + 'npx prettier '.Hyde::pathToRelative(Hyde::getSiteOutputPath($path)).'/ --write --bracket-same-line', 'Prettifying code!', 'prettify code' ); diff --git a/src/Concerns/Internal/FluentPathHelpers.php b/src/Concerns/Internal/FluentPathHelpers.php index 0656890f..20ec0f3e 100644 --- a/src/Concerns/Internal/FluentPathHelpers.php +++ b/src/Concerns/Internal/FluentPathHelpers.php @@ -68,15 +68,6 @@ public static function getSiteOutputPath(string $path = ''): string return StaticPageBuilder::$outputPath.DIRECTORY_SEPARATOR.$path; } - /** - * Get the relative path to the compiled site directory, or a file within it. - * @deprecated use Hyde::pathToRelative() instead - */ - public static function getRelativeSiteOutputPath(string $path = ''): string - { - return static::pathToRelative(static::getSiteOutputPath($path)); - } - /** * Decode an absolute path created with a Hyde::path() helper into its relative counterpart. */ diff --git a/tests/Unit/FluentPathHelpersTest.php b/tests/Unit/FluentPathHelpersTest.php index c55db8f3..8bc07efa 100644 --- a/tests/Unit/FluentPathHelpersTest.php +++ b/tests/Unit/FluentPathHelpersTest.php @@ -118,33 +118,12 @@ public function test_get_site_output_path_returns_absolute_path() ); } - public function test_get_relative_site_output_path_returns_relative_path() - { - $this->assertEquals( - '_site', - Hyde::getRelativeSiteOutputPath() - ); - } - - public function test_get_relative_site_output_path_returns_relative_path_to_file() - { - $this->assertEquals( - '_site'.DIRECTORY_SEPARATOR.'foo.html', - Hyde::getRelativeSiteOutputPath('foo.html') - ); - } - - public function test_site_output_path_helpers_ignore_trailing_slashes() + public function test_site_output_path_helper_ignores_trailing_slashes() { $this->assertEquals( Hyde::path('_site'.DIRECTORY_SEPARATOR.'foo.html'), Hyde::getSiteOutputPath('/foo.html/') ); - - $this->assertEquals( - '_site'.DIRECTORY_SEPARATOR.'foo.html', - Hyde::getRelativeSiteOutputPath('/foo.html/') - ); } public function test_path_to_relative_helper_decodes_hyde_path_into_relative() From ea1ab98910c56c0402f631c5a846480a796f5efa Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 16 May 2022 16:47:52 +0200 Subject: [PATCH 26/27] Deprecate method for getting output paths --- src/Commands/HydeRebuildStaticSiteCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/HydeRebuildStaticSiteCommand.php b/src/Commands/HydeRebuildStaticSiteCommand.php index 556abfdc..7021d8b1 100644 --- a/src/Commands/HydeRebuildStaticSiteCommand.php +++ b/src/Commands/HydeRebuildStaticSiteCommand.php @@ -128,6 +128,7 @@ public function handleException(Exception $exception): int /** * Get the output path for the given source file path. * Will fall back to the input path when using non-standard source paths. + * @deprecated, reimplementing path information in StaticPageBuilder * * @param string $path * @return string From 28130977aec421126b289ec101d359fad6310f8e Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 16 May 2022 14:49:13 +0000 Subject: [PATCH 27/27] Apply fixes from StyleCI --- src/Commands/HydeRebuildStaticSiteCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/HydeRebuildStaticSiteCommand.php b/src/Commands/HydeRebuildStaticSiteCommand.php index 7021d8b1..f522702c 100644 --- a/src/Commands/HydeRebuildStaticSiteCommand.php +++ b/src/Commands/HydeRebuildStaticSiteCommand.php @@ -128,6 +128,7 @@ public function handleException(Exception $exception): int /** * Get the output path for the given source file path. * Will fall back to the input path when using non-standard source paths. + * * @deprecated, reimplementing path information in StaticPageBuilder * * @param string $path