From a5168cf59ac6b6c8d1ec6ada57eaa85081a16c98 Mon Sep 17 00:00:00 2001 From: Caen De Silva <95144705+caendesilva@users.noreply.github.com> Date: Mon, 21 Mar 2022 14:38:24 +0100 Subject: [PATCH 01/42] Fix order fallback should use strict equality --- app/Actions/GeneratesDocumentationSidebar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Actions/GeneratesDocumentationSidebar.php b/app/Actions/GeneratesDocumentationSidebar.php index 797c97f..aa475f9 100644 --- a/app/Actions/GeneratesDocumentationSidebar.php +++ b/app/Actions/GeneratesDocumentationSidebar.php @@ -34,7 +34,7 @@ public static function get(string $current = ""): array $order = array_search($slug, $orderArray); - if ($order !== false) { + if ($order === false) { $order = 999; } From ed6f438b3334839f11fe05dca02369f131139dfe Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 16:09:22 +0100 Subject: [PATCH 02/42] Add helper to get an absolute path from a supplied relative path --- app/Commands/Debug.php | 5 ++++ app/Hyde/Hyde.php | 22 ++++++++++++++++++ tests/Unit/HydePathTest.php | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/Unit/HydePathTest.php diff --git a/app/Commands/Debug.php b/app/Commands/Debug.php index a9695ef..74e6a69 100644 --- a/app/Commands/Debug.php +++ b/app/Commands/Debug.php @@ -3,6 +3,7 @@ namespace App\Commands; use App\Actions\Installer\Installer; +use App\Hyde\Hyde; use LaravelZero\Framework\Commands\Command; class Debug extends Command @@ -30,6 +31,10 @@ public function handle(): int { $this->info('HydePHP Debug Screen'); + $this->newLine(); + $this->line('Project directory:'); + $this->line(' > ' . Hyde::path()); + $this->newLine(); $this->line('Enabled features:'); diff --git a/app/Hyde/Hyde.php b/app/Hyde/Hyde.php index 89b8a8c..0172bf3 100644 --- a/app/Hyde/Hyde.php +++ b/app/Hyde/Hyde.php @@ -18,4 +18,26 @@ public static function hasTorchlight(): bool { return (config('torchlight.token') !== null); } + + /** + * Get an absolute path from a supplied relative path. + * + * The function returns the fully qualified path to your site's root directory. + * + * You may also use the function to generate a fully qualified path to a given file + * relative to the project root directory when supplying the path argument. + * + * @param string $path + * @return string + */ + public static function path(string $path = ''): string + { + if (empty($path)) { + return getcwd(); + } + + $path = trim($path, '/\\'); + + return getcwd() . DIRECTORY_SEPARATOR . $path; + } } diff --git a/tests/Unit/HydePathTest.php b/tests/Unit/HydePathTest.php new file mode 100644 index 0000000..92c8fe7 --- /dev/null +++ b/tests/Unit/HydePathTest.php @@ -0,0 +1,46 @@ +toBeTrue(); +}); + +test('string is returned', function () { + expect(Hyde::path())->toBeString(); +}); + +test('returned directory contains content expected to be in the project directory', + function () { + expect( + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . 'hyde') && + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_pages') && + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_posts') && + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_site') + )->toBeTrue(); + } +); + +test('method returns qualified file path when supplied with argument', function () { + expect(Hyde::path('file.php'))->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'file.php'); +}); + +test('method strips trailing directory separators from argument', function () { + expect(Hyde::path('\\/file.php/'))->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'file.php'); +}); + +test('method returns expected value for nested path arguments', function () { + expect(Hyde::path('directory/file.php')) + ->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'directory/file.php'); +}); + +test('method returns expected value regardless of trailing directory separators in argument', function () { + expect(Hyde::path('directory/file.php/')) + ->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'directory/file.php'); + expect(Hyde::path('/directory/file.php/')) + ->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'directory/file.php'); + expect(Hyde::path('\\/directory/file.php/')) + ->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'directory/file.php'); +}); From d6d9998dbe0e282c7e70b7f6edd35801b047928e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 16:29:04 +0100 Subject: [PATCH 03/42] Remove old tests, and use new path helper in unit tests --- tests/Feature/InspireCommandTest.php | 5 ----- tests/Unit/CreatesDefaultDirectoriesTest.php | 3 ++- tests/Unit/ExampleTest.php | 5 ----- .../{HydePathTest.php => HydePathHelperTest.php} | 2 +- tests/Unit/MarkdownPostParserTest.php | 15 +++++++++++++-- 5 files changed, 16 insertions(+), 14 deletions(-) delete mode 100644 tests/Feature/InspireCommandTest.php delete mode 100644 tests/Unit/ExampleTest.php rename tests/Unit/{HydePathTest.php => HydePathHelperTest.php} (99%) diff --git a/tests/Feature/InspireCommandTest.php b/tests/Feature/InspireCommandTest.php deleted file mode 100644 index 58c71a1..0000000 --- a/tests/Feature/InspireCommandTest.php +++ /dev/null @@ -1,5 +0,0 @@ -artisan('inspire')->assertExitCode(0); -}); diff --git a/tests/Unit/CreatesDefaultDirectoriesTest.php b/tests/Unit/CreatesDefaultDirectoriesTest.php index 40daa35..c1f8927 100644 --- a/tests/Unit/CreatesDefaultDirectoriesTest.php +++ b/tests/Unit/CreatesDefaultDirectoriesTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use App\Actions\CreatesDefaultDirectories; +use App\Hyde\Hyde; class CreatesDefaultDirectoriesTest extends TestCase { @@ -22,7 +23,7 @@ class CreatesDefaultDirectoriesTest extends TestCase public function testDefaultDirectoriesAreCreated() { foreach (CreatesDefaultDirectories::getRequiredDirectories() as $directory) { - $this->assertTrue(is_dir(realpath("./$directory"))); + $this->assertTrue(is_dir(Hyde::path($directory))); } } } diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index 61cd84c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -}); diff --git a/tests/Unit/HydePathTest.php b/tests/Unit/HydePathHelperTest.php similarity index 99% rename from tests/Unit/HydePathTest.php rename to tests/Unit/HydePathHelperTest.php index 92c8fe7..58c7490 100644 --- a/tests/Unit/HydePathTest.php +++ b/tests/Unit/HydePathHelperTest.php @@ -15,7 +15,7 @@ test('returned directory contains content expected to be in the project directory', function () { expect( - file_exists(Hyde::path() . DIRECTORY_SEPARATOR . 'hyde') && + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . 'hyde') && file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_pages') && file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_posts') && file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_site') diff --git a/tests/Unit/MarkdownPostParserTest.php b/tests/Unit/MarkdownPostParserTest.php index 3276934..7d193fd 100644 --- a/tests/Unit/MarkdownPostParserTest.php +++ b/tests/Unit/MarkdownPostParserTest.php @@ -2,6 +2,7 @@ namespace Tests\Unit; +use App\Hyde\Hyde; use App\Hyde\MarkdownPostParser; use App\Hyde\Models\MarkdownPost; use PHPUnit\Framework\TestCase; @@ -17,7 +18,7 @@ protected function setUp(): void parent::setUp(); // Create a Markdown file to work with - copy(realpath('./tests') . '/_stubs/_posts/test-parser-post.md', $this->getPath()); + copy(Hyde::path('tests/_stubs/_posts/test-parser-post.md'), $this->getPath()); } /** @@ -39,7 +40,7 @@ protected function tearDown(): void */ public function getPath(): string { - return realpath('./_posts') . '/test-parser-post.md'; + return Hyde::path('_posts/test-parser-post.md'); } public function testCanParseMarkdownFile() @@ -47,9 +48,19 @@ public function testCanParseMarkdownFile() $post = (new MarkdownPostParser('test-parser-post'))->get(); $this->assertInstanceOf(MarkdownPost::class, $post); $this->assertCount(4, ($post->matter)); + $this->assertIsArray($post->matter); $this->assertIsString($post->body); $this->assertIsString($post->slug); $this->assertTrue(strlen($post->body) > 32); $this->assertTrue(strlen($post->slug) > 8); } + + public function testParsedMarkdownPostContainsValidFrontMatter() + { + $post = (new MarkdownPostParser('test-parser-post'))->get(); + $this->assertEquals('My New Post', $post->matter['title']); + $this->assertEquals('Mr. Hyde', $post->matter['author']); + $this->assertEquals('blog', $post->matter['category']); + $this->assertEquals('test-parser-post', $post->matter['slug']); + } } From 9605de15ec19884cba56fdefcf4e0ac2f2b63339 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 16:42:09 +0100 Subject: [PATCH 04/42] Use the Hyde path helper --- app/Commands/BuildStaticSiteCommand.php | 9 +++++---- app/Commands/MakeValidatorCommand.php | 13 +++++++------ app/Commands/Publish404PageCommand.php | 9 +++++---- .../Feature/Commands/Publish404PageCommandTest.php | 5 +++-- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/Commands/BuildStaticSiteCommand.php b/app/Commands/BuildStaticSiteCommand.php index cc41321..7f350f1 100644 --- a/app/Commands/BuildStaticSiteCommand.php +++ b/app/Commands/BuildStaticSiteCommand.php @@ -7,6 +7,7 @@ use App\Hyde\Services\CollectionService; use App\Hyde\DocumentationPageParser; use App\Hyde\Features; +use App\Hyde\Hyde; use App\Hyde\MarkdownPostParser; use App\Hyde\MarkdownPageParser; use App\Hyde\StaticPageBuilder; @@ -58,12 +59,12 @@ public function handle(): int } $this->line('Transferring Media Assets...'); - $files = realpath('_media') . DIRECTORY_SEPARATOR . ("*.{png,svg,jpg,jpeg,gif,ico}"); - $this->withProgressBar(glob($files, GLOB_BRACE), function ($filepath) { + $this->withProgressBar(glob(Hyde::path('_media/*.{png,svg,jpg,jpeg,gif,ico}'), GLOB_BRACE), function ($filepath) { if ($this->getOutput()->isVeryVerbose()) { $this->line(' > Copying media file ' . basename($filepath) . ' to the output media directory'); } - copy($filepath, realpath('_site/media') . DIRECTORY_SEPARATOR . basename($filepath)); + + copy($filepath, Hyde::path('_site/media/'. basename($filepath))); }); if (Features::hasBlogPosts()) { @@ -119,7 +120,7 @@ public function handle(): int $this->info('Congratulations! 🎉 Your static site has been built!'); $this->info(sprintf( "Your new homepage is stored here -> %s", - base_path('_site' . DIRECTORY_SEPARATOR . 'index.html') + Hyde::path('_site/index.html') )); return 0; diff --git a/app/Commands/MakeValidatorCommand.php b/app/Commands/MakeValidatorCommand.php index a1c3cdb..3ad981a 100644 --- a/app/Commands/MakeValidatorCommand.php +++ b/app/Commands/MakeValidatorCommand.php @@ -2,8 +2,9 @@ namespace App\Commands; +use App\Hyde\Hyde; use LaravelZero\Framework\Commands\Command; -use Illuminate\Support\Str; +use Illuminate\Support\Str; class MakeValidatorCommand extends Command { @@ -24,9 +25,9 @@ class MakeValidatorCommand extends Command /** * Execute the console command. * - * @return mixed + * @return int */ - public function handle() + public function handle(): int { $this->info('Creating new Validation Test!'); $name = $this->option('name') ?? $this->ask('What does the validator do?'); @@ -37,16 +38,16 @@ public function handle() "group('validators'); "; - $path = realpath('tests/Validators') . DIRECTORY_SEPARATOR . $slug; + $path = Hyde::path("tests/Validators/$slug"); if (file_exists($path) && !$this->option('force')) { $this->error('Validator already exists!'); return 409; - } + } file_put_contents($path, $content); diff --git a/app/Commands/Publish404PageCommand.php b/app/Commands/Publish404PageCommand.php index 56f1b75..9f961b6 100644 --- a/app/Commands/Publish404PageCommand.php +++ b/app/Commands/Publish404PageCommand.php @@ -2,6 +2,7 @@ namespace App\Commands; +use App\Hyde\Hyde; use LaravelZero\Framework\Commands\Command; class Publish404PageCommand extends Command @@ -41,13 +42,13 @@ public function handle() } if ($type === 'blade') { - $source = realpath('src/resources/stubs') . DIRECTORY_SEPARATOR . '404.blade.php'; - $path = realpath('resources/views/pages') . DIRECTORY_SEPARATOR . '404.blade.php'; + $source = Hyde::path('src/resources/stubs/404.blade.php'); + $path = Hyde::path('resources/views/pages/404.blade.php'); } if ($type === 'markdown') { - $source = realpath('src/resources/stubs') . DIRECTORY_SEPARATOR . '404.md'; - $path = realpath('_pages') . DIRECTORY_SEPARATOR . '404.md'; + $source = Hyde::path('src/resources/stubs/404.md'); + $path = Hyde::path('_pages/404.md'); } if (file_exists($path) && !$this->option('force')) { diff --git a/tests/Feature/Commands/Publish404PageCommandTest.php b/tests/Feature/Commands/Publish404PageCommandTest.php index 4faa058..ea98686 100644 --- a/tests/Feature/Commands/Publish404PageCommandTest.php +++ b/tests/Feature/Commands/Publish404PageCommandTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Commands; +use App\Hyde\Hyde; use Tests\TestCase; class Publish404PageCommandTest extends TestCase @@ -40,12 +41,12 @@ private function unlink(): void private function getBladePath(): string { - return realpath('resources/views/pages') . DIRECTORY_SEPARATOR . '404.blade.php'; + return Hyde::path('resources/views/pages/404.blade.php'); } private function getMarkdownPath(): string { - return realpath('_pages') . DIRECTORY_SEPARATOR . '404.md'; + return Hyde::path('_pages/404.md'); } public function test_command_exists() From f3d9ef5555253a07acf6f3e22a24e1ab94d0164f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 16:59:39 +0100 Subject: [PATCH 05/42] Refactor to replace realpath with path helper --- app/Actions/CreatesDefaultDirectories.php | 3 ++- app/Actions/CreatesNewMarkdownPostFile.php | 9 +++++---- app/Commands/Validate.php | 4 ++-- app/Hyde/Actions/MarkdownConverter.php | 4 ++-- app/Hyde/DocumentationPageParser.php | 7 ++++++- app/Hyde/MarkdownPageParser.php | 5 +++-- app/Hyde/MarkdownPostParser.php | 5 +++-- tests/Feature/Commands/MakePostCommandTest.php | 3 ++- tests/Validators/CheckIfA404PageExistsTest.php | 6 ++++-- tests/Validators/CheckThatAnIndexFileExistsTest.php | 6 ++++-- 10 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/Actions/CreatesDefaultDirectories.php b/app/Actions/CreatesDefaultDirectories.php index dc02d8c..5766863 100644 --- a/app/Actions/CreatesDefaultDirectories.php +++ b/app/Actions/CreatesDefaultDirectories.php @@ -2,6 +2,7 @@ namespace App\Actions; +use App\Hyde\Hyde; use JetBrains\PhpStorm\Pure; class CreatesDefaultDirectories @@ -22,7 +23,7 @@ public function __invoke(): void { foreach ($this->requiredDirectories as $directory) { // Does the directory exist? // Otherwise, create it. - realpath("./$directory") || mkdir(realpath('.') . "/$directory"); + is_dir(Hyde::path($directory)) || mkdir(Hyde::path($directory)); } } diff --git a/app/Actions/CreatesNewMarkdownPostFile.php b/app/Actions/CreatesNewMarkdownPostFile.php index 1bbea20..722e269 100644 --- a/app/Actions/CreatesNewMarkdownPostFile.php +++ b/app/Actions/CreatesNewMarkdownPostFile.php @@ -3,6 +3,7 @@ namespace App\Actions; use Exception; +use App\Hyde\Hyde; use Illuminate\Support\Str; class CreatesNewMarkdownPostFile @@ -47,15 +48,14 @@ public function __construct( /** * Save the class object to a Markdown file. * - * @todo Remove the slug key from the generated front matter as it is not parsed - * * @param bool $force Should the file be created even if a file with the same path already exists? * @return string|false Returns the path to the file if successful, or false if the file could not be saved. * @throws Exception if a file with the same slug already exists and the force flag is not set. */ public function save(bool $force = false): string|false { - $path = realpath('./_posts') . DIRECTORY_SEPARATOR . "$this->slug.md"; + + $path = Hyde::path("_posts/$this->slug.md"); if ($force !== true && file_exists($path)) { throw new Exception("File at $path already exists! ", 409); @@ -65,7 +65,8 @@ public function save(bool $force = false): string|false unset($arrayWithoutSlug['slug']); - $contents = (new ConvertsArrayToFrontMatter)->execute($arrayWithoutSlug) . "\n## Write something awesome.\n\n"; + $contents = (new ConvertsArrayToFrontMatter)->execute($arrayWithoutSlug) . + "\n## Write something awesome.\n\n"; return file_put_contents($path, $contents) ? $path : false; } diff --git a/app/Commands/Validate.php b/app/Commands/Validate.php index dd411bf..f77fb24 100644 --- a/app/Commands/Validate.php +++ b/app/Commands/Validate.php @@ -2,7 +2,7 @@ namespace App\Commands; -use Illuminate\Console\Scheduling\Schedule; +use App\Hyde\Hyde; use LaravelZero\Framework\Commands\Command; class Validate extends Command @@ -30,7 +30,7 @@ public function handle() { $this->info('Running validation tests!'); - $this->line(shell_exec(realpath('./vendor/bin/pest') . ' --group=validators')); + $this->line(shell_exec(Hyde::path('vendor/bin/pest') . ' --group=validators')); $this->info('All done!'); } diff --git a/app/Hyde/Actions/MarkdownConverter.php b/app/Hyde/Actions/MarkdownConverter.php index 5280ef2..9071750 100644 --- a/app/Hyde/Actions/MarkdownConverter.php +++ b/app/Hyde/Actions/MarkdownConverter.php @@ -33,9 +33,9 @@ public static function parse(string $markdown): string if (Hyde::hasTorchlight() && config('torchlight.attribution', true) && str_contains($html, 'Syntax highlighted by torchlight.dev')) { - $html .= file_get_contents(realpath('src/resources/stubs') . DIRECTORY_SEPARATOR . 'torchlight-badge.html'); + $html .= file_get_contents(Hyde::path('src/resources/stubs/torchlight-badge.html')); } - + return $html; } } diff --git a/app/Hyde/DocumentationPageParser.php b/app/Hyde/DocumentationPageParser.php index 99d53cb..c22cf26 100644 --- a/app/Hyde/DocumentationPageParser.php +++ b/app/Hyde/DocumentationPageParser.php @@ -2,6 +2,7 @@ namespace App\Hyde; +use App\Hyde\Hyde; use App\Hyde\Models\DocumentationPage; use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\Pure; @@ -26,6 +27,10 @@ class DocumentationPageParser */ public string $body; + /** + * The page title + * @var string + */ public string $title; /** @@ -35,7 +40,7 @@ class DocumentationPageParser */ public function __construct(protected string $slug) { - $this->filepath = realpath('./_docs') . "/$slug.md"; + $this->filepath = Hyde::path("_docs/$slug.md"); if (!file_exists($this->filepath)) { throw new Exception("File _docs/$slug.md not found.", 404); } diff --git a/app/Hyde/MarkdownPageParser.php b/app/Hyde/MarkdownPageParser.php index 8bc6060..832e9a3 100644 --- a/app/Hyde/MarkdownPageParser.php +++ b/app/Hyde/MarkdownPageParser.php @@ -2,11 +2,12 @@ namespace App\Hyde; +use App\Hyde\Hyde; use App\Hyde\Models\MarkdownPage; -use Exception; use JetBrains\PhpStorm\ArrayShape; use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\Pure; +use Exception; /** * Parses a Markdown file into an object with support for Front Matter. @@ -39,7 +40,7 @@ class MarkdownPageParser */ public function __construct(protected string $slug) { - $this->filepath = realpath('./_pages') . "/$slug.md"; + $this->filepath = Hyde::path("_pages/$slug.md"); if (!file_exists($this->filepath)) { throw new Exception("File _pages/$slug.md not found.", 404); } diff --git a/app/Hyde/MarkdownPostParser.php b/app/Hyde/MarkdownPostParser.php index db27d21..f074028 100644 --- a/app/Hyde/MarkdownPostParser.php +++ b/app/Hyde/MarkdownPostParser.php @@ -2,11 +2,12 @@ namespace App\Hyde; +use App\Hyde\Hyde; use App\Hyde\Models\MarkdownPost; -use Exception; use JetBrains\PhpStorm\ArrayShape; use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\Pure; +use Exception; /** * Parses a Markdown file into an object with support for Front Matter. @@ -39,7 +40,7 @@ class MarkdownPostParser */ public function __construct(protected string $slug) { - $this->filepath = realpath('./_posts') . "/$slug.md"; + $this->filepath = Hyde::path("_posts/$slug.md"); if (!file_exists($this->filepath)) { throw new Exception("File _posts/$slug.md not found.", 404); } diff --git a/tests/Feature/Commands/MakePostCommandTest.php b/tests/Feature/Commands/MakePostCommandTest.php index f8550de..85b34e8 100644 --- a/tests/Feature/Commands/MakePostCommandTest.php +++ b/tests/Feature/Commands/MakePostCommandTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Commands; +use App\Hyde\Hyde; use Tests\TestCase; class MakePostCommandTest extends TestCase @@ -13,7 +14,7 @@ class MakePostCommandTest extends TestCase */ public function getPath(): string { - return realpath('./_posts') . '/test-post.md'; + return Hyde::path('_posts/test-post.md'); } /** diff --git a/tests/Validators/CheckIfA404PageExistsTest.php b/tests/Validators/CheckIfA404PageExistsTest.php index e7b6cfa..8bf61b3 100644 --- a/tests/Validators/CheckIfA404PageExistsTest.php +++ b/tests/Validators/CheckIfA404PageExistsTest.php @@ -1,8 +1,10 @@ addWarning('Could not find an 404.md or 404.blade.php file! You can scaffold one using `php hyde publish:404`'); diff --git a/tests/Validators/CheckThatAnIndexFileExistsTest.php b/tests/Validators/CheckThatAnIndexFileExistsTest.php index d0c2e13..5c4051d 100644 --- a/tests/Validators/CheckThatAnIndexFileExistsTest.php +++ b/tests/Validators/CheckThatAnIndexFileExistsTest.php @@ -1,8 +1,10 @@ addWarning('Could not find an index.md or index.blade.php file!'); From c2d745de5fa3c198b019632258ba521826669c95 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 17:13:19 +0100 Subject: [PATCH 06/42] Replace base_path with Hyde path helper --- app/Actions/GeneratesNavigationMenu.php | 3 ++- app/Hyde/Actions/GetMarkdownPostList.php | 4 +++- app/Hyde/Models/DocumentationPage.php | 4 +++- app/Hyde/Models/MarkdownPage.php | 4 +++- app/Hyde/Models/MarkdownPost.php | 3 ++- app/Hyde/Services/CollectionService.php | 9 +++++---- app/Hyde/StaticPageBuilder.php | 4 ++-- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/Actions/GeneratesNavigationMenu.php b/app/Actions/GeneratesNavigationMenu.php index a6dfcd4..80f216d 100644 --- a/app/Actions/GeneratesNavigationMenu.php +++ b/app/Actions/GeneratesNavigationMenu.php @@ -3,6 +3,7 @@ namespace App\Actions; use App\Hyde\Features; +use App\Hyde\Hyde; use App\Hyde\Models\MarkdownPage; use Illuminate\Support\Str; @@ -151,7 +152,7 @@ private function getListOfCustomPages(): array { $array = []; - foreach (glob(base_path('resources/views/pages/*.blade.php')) as $path) { + foreach (glob(Hyde::path('resources/views/pages/*.blade.php')) as $path) { $array[] = basename($path, '.blade.php'); } diff --git a/app/Hyde/Actions/GetMarkdownPostList.php b/app/Hyde/Actions/GetMarkdownPostList.php index 8996bb3..5bde2bd 100644 --- a/app/Hyde/Actions/GetMarkdownPostList.php +++ b/app/Hyde/Actions/GetMarkdownPostList.php @@ -2,6 +2,8 @@ namespace App\Hyde\Actions; +use App\Hyde\Hyde; + /** * Creates and returns a list of markdown paths * @deprecated as it will be moved into a static method in the post class @@ -15,7 +17,7 @@ public function execute(): array { $array = []; - foreach (glob(base_path('_posts/*.md')) as $filepath) { + foreach (glob(Hyde::path('_posts/*.md')) as $filepath) { $array[basename($filepath, '.md')] = $filepath; } diff --git a/app/Hyde/Models/DocumentationPage.php b/app/Hyde/Models/DocumentationPage.php index 2a1a287..73d4542 100644 --- a/app/Hyde/Models/DocumentationPage.php +++ b/app/Hyde/Models/DocumentationPage.php @@ -2,6 +2,8 @@ namespace App\Hyde\Models; +use App\Hyde\Hyde; + /** * A simple class that contains the content of a Documentation Page. */ @@ -47,7 +49,7 @@ public static function allAsArray(): array { $array = []; - foreach (glob(base_path('_docs/*.md')) as $filepath) { + foreach (glob(Hyde::path('_docs/*.md')) as $filepath) { $array[basename($filepath, '.md')] = $filepath; } diff --git a/app/Hyde/Models/MarkdownPage.php b/app/Hyde/Models/MarkdownPage.php index 7c38187..59d438e 100644 --- a/app/Hyde/Models/MarkdownPage.php +++ b/app/Hyde/Models/MarkdownPage.php @@ -2,6 +2,8 @@ namespace App\Hyde\Models; +use App\Hyde\Hyde; + /** * A simple class that contains the content of a basic Markdown Page. */ @@ -48,7 +50,7 @@ public static function allAsArray(): array { $array = []; - foreach (glob(base_path('_pages/*.md')) as $filepath) { + foreach (glob(Hyde::path('_pages/*.md')) as $filepath) { $array[basename($filepath, '.md')] = $filepath; } diff --git a/app/Hyde/Models/MarkdownPost.php b/app/Hyde/Models/MarkdownPost.php index 7f653e6..796ef4d 100644 --- a/app/Hyde/Models/MarkdownPost.php +++ b/app/Hyde/Models/MarkdownPost.php @@ -2,6 +2,7 @@ namespace App\Hyde\Models; +use App\Hyde\Hyde; use App\Hyde\MarkdownPostParser; use Illuminate\Support\Collection; @@ -50,7 +51,7 @@ public static function getCollection(): Collection { $collection = new Collection(); - foreach (glob(base_path('_posts/*.md')) as $filepath) { + foreach (glob(Hyde::path('_posts/*.md')) as $filepath) { $collection->push((new MarkdownPostParser(basename($filepath, '.md')))->get()); } diff --git a/app/Hyde/Services/CollectionService.php b/app/Hyde/Services/CollectionService.php index eb27221..e9dcf0f 100644 --- a/app/Hyde/Services/CollectionService.php +++ b/app/Hyde/Services/CollectionService.php @@ -2,6 +2,7 @@ namespace App\Hyde\Services; +use App\Hyde\Hyde; use App\Hyde\Models\BladePage; use App\Hyde\Models\MarkdownPage; use App\Hyde\Models\MarkdownPost; @@ -47,7 +48,7 @@ public static function getBladePageList(): array { $array = []; - foreach (glob(base_path('resources/views/pages/*.blade.php')) as $filepath) { + foreach (glob(Hyde::path('resources/views/pages/*.blade.php')) as $filepath) { $array[] = basename($filepath, '.blade.php'); } @@ -62,7 +63,7 @@ public static function getMarkdownPageList(): array { $array = []; - foreach (glob(base_path('_pages/*.md')) as $filepath) { + foreach (glob(Hyde::path('_pages/*.md')) as $filepath) { $array[] = basename($filepath, '.md'); } @@ -77,7 +78,7 @@ public static function getMarkdownPostList(): array { $array = []; - foreach (glob(base_path('_posts/*.md')) as $filepath) { + foreach (glob(Hyde::path('_posts/*.md')) as $filepath) { $array[] = basename($filepath, '.md'); } @@ -93,7 +94,7 @@ public static function getDocumentationPageList(): array { $array = []; - foreach (glob(base_path('_docs/*.md')) as $filepath) { + foreach (glob(Hyde::path('_docs/*.md')) as $filepath) { $array[] = basename($filepath, '.md'); } diff --git a/app/Hyde/StaticPageBuilder.php b/app/Hyde/StaticPageBuilder.php index 72ab765..c63032b 100644 --- a/app/Hyde/StaticPageBuilder.php +++ b/app/Hyde/StaticPageBuilder.php @@ -73,7 +73,7 @@ public function getDebugOutput(bool $relativeFilePath = true): array return [ 'createdFileSize' => $this->createdFileSize, 'createdFilePath' => $relativeFilePath - ? str_replace(base_path(), '', $this->createdFilePath) + ? str_replace(Hyde::path(), '', $this->createdFilePath) : $this->createdFilePath , ]; } @@ -85,7 +85,7 @@ public function getDebugOutput(bool $relativeFilePath = true): array */ private function save(string $location, string $contents): bool|int { - $path = base_path('./_site') . '/' . $location . '.html'; + $path = Hyde::path("_site/$location.html"); $this->createdFilePath = $path; return file_put_contents($path, $contents); } From b6c52c1b0ff121b371f303ce096f3e2b2f9a9386 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 17:17:00 +0100 Subject: [PATCH 07/42] Format to PSR2 --- app/Actions/ConvertsFooterMarkdown.php | 9 ++-- app/Actions/CreatesNewMarkdownPostFile.php | 2 +- app/Actions/GeneratesNavigationMenu.php | 4 +- app/Commands/BuildStaticSiteCommand.php | 50 ++++++++++++++-------- app/Commands/Publish404PageCommand.php | 5 ++- app/Hyde/Features.php | 17 ++++---- app/Hyde/Hyde.php | 2 +- 7 files changed, 54 insertions(+), 35 deletions(-) diff --git a/app/Actions/ConvertsFooterMarkdown.php b/app/Actions/ConvertsFooterMarkdown.php index 31b1718..68587c7 100644 --- a/app/Actions/ConvertsFooterMarkdown.php +++ b/app/Actions/ConvertsFooterMarkdown.php @@ -8,13 +8,16 @@ class ConvertsFooterMarkdown { /** * Convert the Markdown text if supplied in the config, - * or fall back to default to generate HTML for the footer. + * or fall back to default to generate HTML for the footer. * * @return string $html */ public static function execute(): string { - return Str::markdown(config('hyde.footer.markdown', 'Site built with the Free and Open Source [HydePHP](https://github.com/hydephp/hyde). - License [MIT](https://github.com/hydephp/hyde/blob/master/LICENSE.md).')); + return Str::markdown(config( + 'hyde.footer.markdown', + 'Site built with the Free and Open Source [HydePHP](https://github.com/hydephp/hyde). + License [MIT](https://github.com/hydephp/hyde/blob/master/LICENSE.md).' + )); } } diff --git a/app/Actions/CreatesNewMarkdownPostFile.php b/app/Actions/CreatesNewMarkdownPostFile.php index 722e269..ce9099d 100644 --- a/app/Actions/CreatesNewMarkdownPostFile.php +++ b/app/Actions/CreatesNewMarkdownPostFile.php @@ -65,7 +65,7 @@ public function save(bool $force = false): string|false unset($arrayWithoutSlug['slug']); - $contents = (new ConvertsArrayToFrontMatter)->execute($arrayWithoutSlug) . + $contents = (new ConvertsArrayToFrontMatter)->execute($arrayWithoutSlug) . "\n## Write something awesome.\n\n"; return file_put_contents($path, $contents) ? $path : false; diff --git a/app/Actions/GeneratesNavigationMenu.php b/app/Actions/GeneratesNavigationMenu.php index 80f216d..9330958 100644 --- a/app/Actions/GeneratesNavigationMenu.php +++ b/app/Actions/GeneratesNavigationMenu.php @@ -45,9 +45,9 @@ public function __construct(string $currentPage) /** * Create the link array - * + * * @todo Cache the base array and only update the 'current' attribute on each request. - * + * * @return array */ private function getLinks(): array diff --git a/app/Commands/BuildStaticSiteCommand.php b/app/Commands/BuildStaticSiteCommand.php index 7f350f1..cc01ceb 100644 --- a/app/Commands/BuildStaticSiteCommand.php +++ b/app/Commands/BuildStaticSiteCommand.php @@ -59,45 +59,61 @@ public function handle(): int } $this->line('Transferring Media Assets...'); - $this->withProgressBar(glob(Hyde::path('_media/*.{png,svg,jpg,jpeg,gif,ico}'), GLOB_BRACE), function ($filepath) { - if ($this->getOutput()->isVeryVerbose()) { - $this->line(' > Copying media file ' . basename($filepath) . ' to the output media directory'); - } + $this->withProgressBar( + glob(Hyde::path('_media/*.{png,svg,jpg,jpeg,gif,ico}'), GLOB_BRACE), + function ($filepath) { + if ($this->getOutput()->isVeryVerbose()) { + $this->line(' > Copying media file ' + . basename($filepath). ' to the output media directory'); + } - copy($filepath, Hyde::path('_site/media/'. basename($filepath))); - }); + copy($filepath, Hyde::path('_site/media/'. basename($filepath))); + } + ); if (Features::hasBlogPosts()) { $this->newLine(2); $this->line('Creating Markdown Posts...'); - $this->withProgressBar(CollectionService::getSourceSlugsOfModels(MarkdownPost::class), function ($slug) { - $this->debug((new StaticPageBuilder((new MarkdownPostParser($slug))->get(), true))->getDebugOutput()); - }); + $this->withProgressBar( + CollectionService::getSourceSlugsOfModels(MarkdownPost::class), + function ($slug) { + $this->debug((new StaticPageBuilder((new MarkdownPostParser($slug))->get(), true)) + ->getDebugOutput()); + } + ); } if (Features::hasMarkdownPages()) { $this->newLine(2); $this->line('Creating Markdown Pages...'); - $this->withProgressBar(CollectionService::getSourceSlugsOfModels(MarkdownPage::class), function ($slug) { - $this->debug((new StaticPageBuilder((new MarkdownPageParser($slug))->get(), true))->getDebugOutput()); - }); + $this->withProgressBar( + CollectionService::getSourceSlugsOfModels(MarkdownPage::class), + function ($slug) { + $this->debug((new StaticPageBuilder((new MarkdownPageParser($slug))->get(), true)) + ->getDebugOutput()); + } + ); } if (Features::hasDocumentationPages()) { $this->newLine(2); $this->line('Creating Documentation Pages...'); - $this->withProgressBar(CollectionService::getSourceSlugsOfModels(DocumentationPage::class), function ($slug) { - $this->debug((new StaticPageBuilder((new DocumentationPageParser($slug))->get(), true))->getDebugOutput()); - }); + $this->withProgressBar( + CollectionService::getSourceSlugsOfModels(DocumentationPage::class), + function ($slug) { + $this->debug((new StaticPageBuilder((new DocumentationPageParser($slug))->get(), true)) + ->getDebugOutput()); + } + ); } - if (Features::hasBladePages()) { + if (Features::hasBladePages()) { $this->newLine(2); $this->line('Creating Blade Pages...'); $this->withProgressBar(CollectionService::getSourceSlugsOfModels(BladePage::class), function ($slug) { $this->debug((new StaticPageBuilder((new BladePage($slug)), true))->getDebugOutput()); }); - } + } $this->newLine(2); diff --git a/app/Commands/Publish404PageCommand.php b/app/Commands/Publish404PageCommand.php index 9f961b6..71bcf64 100644 --- a/app/Commands/Publish404PageCommand.php +++ b/app/Commands/Publish404PageCommand.php @@ -12,7 +12,9 @@ class Publish404PageCommand extends Command * * @var string */ - protected $signature = 'publish:404 {--type= : The view to publish. Must be Blade or Markdown } {--force : Overwrite existing files}'; + protected $signature = 'publish:404 + {--type= : The view to publish. Must be Blade or Markdown } + {--force : Overwrite existing files}'; /** * The description of the command. @@ -61,5 +63,4 @@ public function handle() $this->info("Created file $path!"); return 0; } - } diff --git a/app/Hyde/Features.php b/app/Hyde/Features.php index 1ddae8c..4579480 100644 --- a/app/Hyde/Features.php +++ b/app/Hyde/Features.php @@ -22,7 +22,7 @@ public static function enabled(string $feature) } - /** + /** * Determine if the site has blog posts enabled. * * @return bool @@ -32,7 +32,7 @@ public static function hasBlogPosts() return static::enabled(static::blogPosts()); } - /** + /** * Determine if the site has custom Blade pages enabled. * * @return bool @@ -42,7 +42,7 @@ public static function hasBladePages() return static::enabled(static::bladePages()); } - /** + /** * Determine if the site has custom Markdown pages enabled. * * @return bool @@ -52,7 +52,7 @@ public static function hasMarkdownPages() return static::enabled(static::markdownPages()); } - /** + /** * Determine if the site has Laradocgen enabled. * * @return bool @@ -63,7 +63,7 @@ public static function hasDocumentationPages() } - /** + /** * Enable the blog post feature. * * @return string @@ -73,7 +73,7 @@ public static function blogPosts() return 'blog-posts'; } - /** + /** * Enable the Blade page feature. * * @return string @@ -83,7 +83,7 @@ public static function bladePages() return 'blade-pages'; } - /** + /** * Enable the Markdown page feature. * * @return string @@ -93,7 +93,7 @@ public static function markdownPages() return 'markdown-pages'; } - /** + /** * Enable the documentation page feature. * * @return string @@ -102,5 +102,4 @@ public static function documentationPages() { return 'documentation-pages'; } - } diff --git a/app/Hyde/Hyde.php b/app/Hyde/Hyde.php index 0172bf3..f269a4e 100644 --- a/app/Hyde/Hyde.php +++ b/app/Hyde/Hyde.php @@ -23,7 +23,7 @@ public static function hasTorchlight(): bool * Get an absolute path from a supplied relative path. * * The function returns the fully qualified path to your site's root directory. - * + * * You may also use the function to generate a fully qualified path to a given file * relative to the project root directory when supplying the path argument. * From af6f119aa117dd483a00ade24769db33bbe78b6f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 18:45:12 +0100 Subject: [PATCH 08/42] Allow file to be opened directly in browser from terminal --- app/Commands/BuildStaticSiteCommand.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Commands/BuildStaticSiteCommand.php b/app/Commands/BuildStaticSiteCommand.php index cc01ceb..8c76042 100644 --- a/app/Commands/BuildStaticSiteCommand.php +++ b/app/Commands/BuildStaticSiteCommand.php @@ -134,10 +134,13 @@ function ($slug) { ) .' seconds. (' . number_format(($execution_time * 1000), 2) . 'ms)'); $this->info('Congratulations! 🎉 Your static site has been built!'); - $this->info(sprintf( - "Your new homepage is stored here -> %s", - Hyde::path('_site/index.html') - )); + echo( + "Your new homepage is stored here -> file://" . str_replace( + '\\', + '/', + realpath(Hyde::path('_site/index.html')) + ) + ); return 0; } From 49f953db19653b9f0d8931bb5b4366609cb18968 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 18:45:12 +0100 Subject: [PATCH 09/42] Allow file to be opened directly in browser from terminal --- app/Commands/BuildStaticSiteCommand.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Commands/BuildStaticSiteCommand.php b/app/Commands/BuildStaticSiteCommand.php index cc01ceb..8c76042 100644 --- a/app/Commands/BuildStaticSiteCommand.php +++ b/app/Commands/BuildStaticSiteCommand.php @@ -134,10 +134,13 @@ function ($slug) { ) .' seconds. (' . number_format(($execution_time * 1000), 2) . 'ms)'); $this->info('Congratulations! 🎉 Your static site has been built!'); - $this->info(sprintf( - "Your new homepage is stored here -> %s", - Hyde::path('_site/index.html') - )); + echo( + "Your new homepage is stored here -> file://" . str_replace( + '\\', + '/', + realpath(Hyde::path('_site/index.html')) + ) + ); return 0; } From fa6dfd8e8fa133c674d41824b04c3a5d9cf33fd9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 18:48:12 +0100 Subject: [PATCH 10/42] Allow the view source directory to be modified at runtime --- app/Hyde/Hyde.php | 9 +++++++++ config/view.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Hyde/Hyde.php b/app/Hyde/Hyde.php index f269a4e..09b51fe 100644 --- a/app/Hyde/Hyde.php +++ b/app/Hyde/Hyde.php @@ -19,6 +19,15 @@ public static function hasTorchlight(): bool return (config('torchlight.token') !== null); } + /** + * Return the path where the Blade views are located + * @return string + */ + public static function viewPath() + { + return resource_path('views') ; + } + /** * Get an absolute path from a supplied relative path. * diff --git a/config/view.php b/config/view.php index d41f749..2ad680f 100644 --- a/config/view.php +++ b/config/view.php @@ -2,7 +2,7 @@ return [ 'paths' => [ - resource_path('views'), + App\Hyde\Hyde::viewPath(), ], 'compiled' => env( From 32c5fcd46212f2863fa05ad07ffe39653e29601e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 20:22:46 +0100 Subject: [PATCH 11/42] Move Actions into Hyde namespace --- app/Commands/MakePostCommand.php | 4 ++-- app/{ => Hyde}/Actions/ConvertsArrayToFrontMatter.php | 2 +- app/{ => Hyde}/Actions/ConvertsFooterMarkdown.php | 3 ++- app/{ => Hyde}/Actions/CreatesDefaultDirectories.php | 2 +- app/{ => Hyde}/Actions/CreatesNewMarkdownPostFile.php | 6 +++--- app/{ => Hyde}/Actions/GeneratesDocumentationSidebar.php | 5 +++-- app/{ => Hyde}/Actions/GeneratesNavigationMenu.php | 3 ++- app/Providers/AppServiceProvider.php | 2 +- resources/views/components/docs/sidebar.blade.php | 2 +- resources/views/layouts/footer.blade.php | 4 ++-- resources/views/layouts/navigation.blade.php | 6 +++--- tests/Unit/CreatesDefaultDirectoriesTest.php | 8 ++++---- 12 files changed, 25 insertions(+), 22 deletions(-) rename app/{ => Hyde}/Actions/ConvertsArrayToFrontMatter.php (94%) rename app/{ => Hyde}/Actions/ConvertsFooterMarkdown.php (91%) rename app/{ => Hyde}/Actions/CreatesDefaultDirectories.php (96%) rename app/{ => Hyde}/Actions/CreatesNewMarkdownPostFile.php (98%) rename app/{ => Hyde}/Actions/GeneratesDocumentationSidebar.php (96%) rename app/{ => Hyde}/Actions/GeneratesNavigationMenu.php (99%) diff --git a/app/Commands/MakePostCommand.php b/app/Commands/MakePostCommand.php index 93ca1dc..bd0a8aa 100644 --- a/app/Commands/MakePostCommand.php +++ b/app/Commands/MakePostCommand.php @@ -2,9 +2,9 @@ namespace App\Commands; -use App\Actions\CreatesNewMarkdownPostFile; -use LaravelZero\Framework\Commands\Command; +use App\Hyde\Actions\CreatesNewMarkdownPostFile; use Exception; +use LaravelZero\Framework\Commands\Command; class MakePostCommand extends Command { diff --git a/app/Actions/ConvertsArrayToFrontMatter.php b/app/Hyde/Actions/ConvertsArrayToFrontMatter.php similarity index 94% rename from app/Actions/ConvertsArrayToFrontMatter.php rename to app/Hyde/Actions/ConvertsArrayToFrontMatter.php index 7980436..e593846 100644 --- a/app/Actions/ConvertsArrayToFrontMatter.php +++ b/app/Hyde/Actions/ConvertsArrayToFrontMatter.php @@ -1,6 +1,6 @@ slug.md"); if ($force !== true && file_exists($path)) { diff --git a/app/Actions/GeneratesDocumentationSidebar.php b/app/Hyde/Actions/GeneratesDocumentationSidebar.php similarity index 96% rename from app/Actions/GeneratesDocumentationSidebar.php rename to app/Hyde/Actions/GeneratesDocumentationSidebar.php index aa475f9..d22c506 100644 --- a/app/Actions/GeneratesDocumentationSidebar.php +++ b/app/Hyde/Actions/GeneratesDocumentationSidebar.php @@ -1,10 +1,11 @@ $slug, 'title' => Str::title(str_replace('-', ' ', $slug)), diff --git a/app/Actions/GeneratesNavigationMenu.php b/app/Hyde/Actions/GeneratesNavigationMenu.php similarity index 99% rename from app/Actions/GeneratesNavigationMenu.php rename to app/Hyde/Actions/GeneratesNavigationMenu.php index 9330958..9c1bc3d 100644 --- a/app/Actions/GeneratesNavigationMenu.php +++ b/app/Hyde/Actions/GeneratesNavigationMenu.php @@ -1,11 +1,12 @@
    - @foreach (App\Actions\GeneratesDocumentationSidebar::get($currentPage) as $item) + @foreach (App\Hyde\Actions\GeneratesDocumentationSidebar::get($currentPage) as $item)
  • - {!! App\Actions\ConvertsFooterMarkdown::execute() !!} + {!! App\Hyde\Actions\ConvertsFooterMarkdown::execute() !!}
    - \ No newline at end of file + diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 837d6f0..f93c339 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -1,5 +1,5 @@ @php - $links = App\Actions\GeneratesNavigationMenu::getNavigationLinks($currentPage); + $links = App\Hyde\Actions\GeneratesNavigationMenu::getNavigationLinks($currentPage); $homeRoute = ($links[array_search('Home', array_column($links, 'title'))])['route'] ?? 'index.html'; @endphp @@ -34,7 +34,7 @@ {{ config('hyde.name', 'HydePHP') }} - + @@ -85,4 +85,4 @@ function hideNavigation() { navigationOpen = false; } - \ No newline at end of file + diff --git a/tests/Unit/CreatesDefaultDirectoriesTest.php b/tests/Unit/CreatesDefaultDirectoriesTest.php index c1f8927..480036d 100644 --- a/tests/Unit/CreatesDefaultDirectoriesTest.php +++ b/tests/Unit/CreatesDefaultDirectoriesTest.php @@ -2,18 +2,18 @@ namespace Tests\Unit; -use PHPUnit\Framework\TestCase; -use App\Actions\CreatesDefaultDirectories; +use App\Hyde\Actions\CreatesDefaultDirectories; use App\Hyde\Hyde; +use PHPUnit\Framework\TestCase; class CreatesDefaultDirectoriesTest extends TestCase { /** * Test if the directories are created. - * + * * Note that the action is called by the Service Provider * when booting, so we don't call the action directly. - * + * * To properly test that it works, you should first * remove the directories manually as the action * will not have anything to do otherwise. From 936684bd6b562f4b2d7626a1070b63ddd4e613d2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 20:39:43 +0100 Subject: [PATCH 12/42] Rename Hyde to Core --- app/{Hyde => Core}/Actions/ConvertsArrayToFrontMatter.php | 0 app/{Hyde => Core}/Actions/ConvertsFooterMarkdown.php | 0 app/{Hyde => Core}/Actions/CreatesDefaultDirectories.php | 0 app/{Hyde => Core}/Actions/CreatesNewMarkdownPostFile.php | 0 app/{Hyde => Core}/Actions/GeneratesDocumentationSidebar.php | 0 app/{Hyde => Core}/Actions/GeneratesNavigationMenu.php | 0 app/{Hyde => Core}/Actions/GetMarkdownPostList.php | 0 app/{Hyde => Core}/Actions/MarkdownConverter.php | 0 app/{Hyde => Core}/Docgen/HydeDocgen.php | 0 app/{Hyde => Core}/DocumentationPageParser.php | 0 app/{Hyde => Core}/Features.php | 0 app/{Hyde => Core}/Hyde.php | 0 app/{Hyde => Core}/MarkdownPageParser.php | 0 app/{Hyde => Core}/MarkdownPostParser.php | 0 app/{Hyde => Core}/Models/BladePage.php | 0 app/{Hyde => Core}/Models/DocumentationPage.php | 0 app/{Hyde => Core}/Models/MarkdownPage.php | 0 app/{Hyde => Core}/Models/MarkdownPost.php | 0 app/{Hyde => Core}/Services/CollectionService.php | 0 app/{Hyde => Core}/StaticPageBuilder.php | 0 20 files changed, 0 insertions(+), 0 deletions(-) rename app/{Hyde => Core}/Actions/ConvertsArrayToFrontMatter.php (100%) rename app/{Hyde => Core}/Actions/ConvertsFooterMarkdown.php (100%) rename app/{Hyde => Core}/Actions/CreatesDefaultDirectories.php (100%) rename app/{Hyde => Core}/Actions/CreatesNewMarkdownPostFile.php (100%) rename app/{Hyde => Core}/Actions/GeneratesDocumentationSidebar.php (100%) rename app/{Hyde => Core}/Actions/GeneratesNavigationMenu.php (100%) rename app/{Hyde => Core}/Actions/GetMarkdownPostList.php (100%) rename app/{Hyde => Core}/Actions/MarkdownConverter.php (100%) rename app/{Hyde => Core}/Docgen/HydeDocgen.php (100%) rename app/{Hyde => Core}/DocumentationPageParser.php (100%) rename app/{Hyde => Core}/Features.php (100%) rename app/{Hyde => Core}/Hyde.php (100%) rename app/{Hyde => Core}/MarkdownPageParser.php (100%) rename app/{Hyde => Core}/MarkdownPostParser.php (100%) rename app/{Hyde => Core}/Models/BladePage.php (100%) rename app/{Hyde => Core}/Models/DocumentationPage.php (100%) rename app/{Hyde => Core}/Models/MarkdownPage.php (100%) rename app/{Hyde => Core}/Models/MarkdownPost.php (100%) rename app/{Hyde => Core}/Services/CollectionService.php (100%) rename app/{Hyde => Core}/StaticPageBuilder.php (100%) diff --git a/app/Hyde/Actions/ConvertsArrayToFrontMatter.php b/app/Core/Actions/ConvertsArrayToFrontMatter.php similarity index 100% rename from app/Hyde/Actions/ConvertsArrayToFrontMatter.php rename to app/Core/Actions/ConvertsArrayToFrontMatter.php diff --git a/app/Hyde/Actions/ConvertsFooterMarkdown.php b/app/Core/Actions/ConvertsFooterMarkdown.php similarity index 100% rename from app/Hyde/Actions/ConvertsFooterMarkdown.php rename to app/Core/Actions/ConvertsFooterMarkdown.php diff --git a/app/Hyde/Actions/CreatesDefaultDirectories.php b/app/Core/Actions/CreatesDefaultDirectories.php similarity index 100% rename from app/Hyde/Actions/CreatesDefaultDirectories.php rename to app/Core/Actions/CreatesDefaultDirectories.php diff --git a/app/Hyde/Actions/CreatesNewMarkdownPostFile.php b/app/Core/Actions/CreatesNewMarkdownPostFile.php similarity index 100% rename from app/Hyde/Actions/CreatesNewMarkdownPostFile.php rename to app/Core/Actions/CreatesNewMarkdownPostFile.php diff --git a/app/Hyde/Actions/GeneratesDocumentationSidebar.php b/app/Core/Actions/GeneratesDocumentationSidebar.php similarity index 100% rename from app/Hyde/Actions/GeneratesDocumentationSidebar.php rename to app/Core/Actions/GeneratesDocumentationSidebar.php diff --git a/app/Hyde/Actions/GeneratesNavigationMenu.php b/app/Core/Actions/GeneratesNavigationMenu.php similarity index 100% rename from app/Hyde/Actions/GeneratesNavigationMenu.php rename to app/Core/Actions/GeneratesNavigationMenu.php diff --git a/app/Hyde/Actions/GetMarkdownPostList.php b/app/Core/Actions/GetMarkdownPostList.php similarity index 100% rename from app/Hyde/Actions/GetMarkdownPostList.php rename to app/Core/Actions/GetMarkdownPostList.php diff --git a/app/Hyde/Actions/MarkdownConverter.php b/app/Core/Actions/MarkdownConverter.php similarity index 100% rename from app/Hyde/Actions/MarkdownConverter.php rename to app/Core/Actions/MarkdownConverter.php diff --git a/app/Hyde/Docgen/HydeDocgen.php b/app/Core/Docgen/HydeDocgen.php similarity index 100% rename from app/Hyde/Docgen/HydeDocgen.php rename to app/Core/Docgen/HydeDocgen.php diff --git a/app/Hyde/DocumentationPageParser.php b/app/Core/DocumentationPageParser.php similarity index 100% rename from app/Hyde/DocumentationPageParser.php rename to app/Core/DocumentationPageParser.php diff --git a/app/Hyde/Features.php b/app/Core/Features.php similarity index 100% rename from app/Hyde/Features.php rename to app/Core/Features.php diff --git a/app/Hyde/Hyde.php b/app/Core/Hyde.php similarity index 100% rename from app/Hyde/Hyde.php rename to app/Core/Hyde.php diff --git a/app/Hyde/MarkdownPageParser.php b/app/Core/MarkdownPageParser.php similarity index 100% rename from app/Hyde/MarkdownPageParser.php rename to app/Core/MarkdownPageParser.php diff --git a/app/Hyde/MarkdownPostParser.php b/app/Core/MarkdownPostParser.php similarity index 100% rename from app/Hyde/MarkdownPostParser.php rename to app/Core/MarkdownPostParser.php diff --git a/app/Hyde/Models/BladePage.php b/app/Core/Models/BladePage.php similarity index 100% rename from app/Hyde/Models/BladePage.php rename to app/Core/Models/BladePage.php diff --git a/app/Hyde/Models/DocumentationPage.php b/app/Core/Models/DocumentationPage.php similarity index 100% rename from app/Hyde/Models/DocumentationPage.php rename to app/Core/Models/DocumentationPage.php diff --git a/app/Hyde/Models/MarkdownPage.php b/app/Core/Models/MarkdownPage.php similarity index 100% rename from app/Hyde/Models/MarkdownPage.php rename to app/Core/Models/MarkdownPage.php diff --git a/app/Hyde/Models/MarkdownPost.php b/app/Core/Models/MarkdownPost.php similarity index 100% rename from app/Hyde/Models/MarkdownPost.php rename to app/Core/Models/MarkdownPost.php diff --git a/app/Hyde/Services/CollectionService.php b/app/Core/Services/CollectionService.php similarity index 100% rename from app/Hyde/Services/CollectionService.php rename to app/Core/Services/CollectionService.php diff --git a/app/Hyde/StaticPageBuilder.php b/app/Core/StaticPageBuilder.php similarity index 100% rename from app/Hyde/StaticPageBuilder.php rename to app/Core/StaticPageBuilder.php From 1cb8d3fdd768030c15abdd8f610613b75e8e1264 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Mar 2022 20:43:19 +0100 Subject: [PATCH 13/42] Update namespace reference to use Core --- app/Commands/BuildStaticSiteCommand.php | 24 +++++++++---------- app/Commands/Debug.php | 2 +- app/Commands/MakePostCommand.php | 2 +- app/Commands/MakeValidatorCommand.php | 2 +- app/Commands/Publish404PageCommand.php | 6 ++--- app/Commands/Validate.php | 2 +- .../Actions/ConvertsArrayToFrontMatter.php | 2 +- app/Core/Actions/ConvertsFooterMarkdown.php | 2 +- .../Actions/CreatesDefaultDirectories.php | 4 ++-- .../Actions/CreatesNewMarkdownPostFile.php | 4 ++-- .../Actions/GeneratesDocumentationSidebar.php | 6 ++--- app/Core/Actions/GeneratesNavigationMenu.php | 8 +++---- app/Core/Actions/GetMarkdownPostList.php | 4 ++-- app/Core/Actions/MarkdownConverter.php | 6 ++--- app/Core/Docgen/HydeDocgen.php | 4 ++-- app/Core/DocumentationPageParser.php | 10 ++++---- app/Core/Features.php | 2 +- app/Core/Hyde.php | 2 +- app/Core/MarkdownPageParser.php | 6 ++--- app/Core/MarkdownPostParser.php | 8 +++---- app/Core/Models/BladePage.php | 2 +- app/Core/Models/DocumentationPage.php | 4 ++-- app/Core/Models/MarkdownPage.php | 4 ++-- app/Core/Models/MarkdownPost.php | 6 ++--- app/Core/Services/CollectionService.php | 12 +++++----- app/Core/StaticPageBuilder.php | 12 +++++----- app/Providers/AppServiceProvider.php | 2 +- config/hyde.php | 16 ++++++------- config/view.php | 2 +- .../views/components/docs/content.blade.php | 2 +- .../views/components/docs/sidebar.blade.php | 2 +- .../views/components/post/article.blade.php | 2 +- resources/views/layouts/footer.blade.php | 2 +- resources/views/layouts/navigation.blade.php | 2 +- resources/views/page.blade.php | 2 +- resources/views/pages/index.blade.php | 6 ++--- .../Feature/Commands/MakePostCommandTest.php | 10 ++++---- .../Commands/Publish404PageCommandTest.php | 12 +++++----- tests/Unit/CreatesDefaultDirectoriesTest.php | 4 ++-- tests/Unit/HydePathHelperTest.php | 2 +- tests/Unit/MarkdownPostParserTest.php | 8 +++---- .../Validators/CheckIfA404PageExistsTest.php | 4 ++-- .../CheckThatAnIndexFileExistsTest.php | 4 ++-- ...tDocumentationPagesHaveAnIndexPageTest.php | 4 ++-- 44 files changed, 116 insertions(+), 116 deletions(-) diff --git a/app/Commands/BuildStaticSiteCommand.php b/app/Commands/BuildStaticSiteCommand.php index 8c76042..172f5bf 100644 --- a/app/Commands/BuildStaticSiteCommand.php +++ b/app/Commands/BuildStaticSiteCommand.php @@ -4,17 +4,17 @@ use Exception; use LaravelZero\Framework\Commands\Command; -use App\Hyde\Services\CollectionService; -use App\Hyde\DocumentationPageParser; -use App\Hyde\Features; -use App\Hyde\Hyde; -use App\Hyde\MarkdownPostParser; -use App\Hyde\MarkdownPageParser; -use App\Hyde\StaticPageBuilder; -use App\Hyde\Models\BladePage; -use App\Hyde\Models\MarkdownPage; -use App\Hyde\Models\MarkdownPost; -use App\Hyde\Models\DocumentationPage; +use App\Core\Services\CollectionService; +use App\Core\DocumentationPageParser; +use App\Core\Features; +use App\Core\Hyde; +use App\Core\MarkdownPostParser; +use App\Core\MarkdownPageParser; +use App\Core\StaticPageBuilder; +use App\Core\Models\BladePage; +use App\Core\Models\MarkdownPage; +use App\Core\Models\MarkdownPost; +use App\Core\Models\DocumentationPage; class BuildStaticSiteCommand extends Command { @@ -66,7 +66,7 @@ function ($filepath) { $this->line(' > Copying media file ' . basename($filepath). ' to the output media directory'); } - + copy($filepath, Hyde::path('_site/media/'. basename($filepath))); } ); diff --git a/app/Commands/Debug.php b/app/Commands/Debug.php index 74e6a69..7bb9cfc 100644 --- a/app/Commands/Debug.php +++ b/app/Commands/Debug.php @@ -3,7 +3,7 @@ namespace App\Commands; use App\Actions\Installer\Installer; -use App\Hyde\Hyde; +use App\Core\Hyde; use LaravelZero\Framework\Commands\Command; class Debug extends Command diff --git a/app/Commands/MakePostCommand.php b/app/Commands/MakePostCommand.php index bd0a8aa..a95e6c0 100644 --- a/app/Commands/MakePostCommand.php +++ b/app/Commands/MakePostCommand.php @@ -2,7 +2,7 @@ namespace App\Commands; -use App\Hyde\Actions\CreatesNewMarkdownPostFile; +use App\Core\Actions\CreatesNewMarkdownPostFile; use Exception; use LaravelZero\Framework\Commands\Command; diff --git a/app/Commands/MakeValidatorCommand.php b/app/Commands/MakeValidatorCommand.php index 3ad981a..77b4d7c 100644 --- a/app/Commands/MakeValidatorCommand.php +++ b/app/Commands/MakeValidatorCommand.php @@ -2,7 +2,7 @@ namespace App\Commands; -use App\Hyde\Hyde; +use App\Core\Hyde; use LaravelZero\Framework\Commands\Command; use Illuminate\Support\Str; diff --git a/app/Commands/Publish404PageCommand.php b/app/Commands/Publish404PageCommand.php index 71bcf64..c19c83e 100644 --- a/app/Commands/Publish404PageCommand.php +++ b/app/Commands/Publish404PageCommand.php @@ -2,7 +2,7 @@ namespace App\Commands; -use App\Hyde\Hyde; +use App\Core\Hyde; use LaravelZero\Framework\Commands\Command; class Publish404PageCommand extends Command @@ -12,7 +12,7 @@ class Publish404PageCommand extends Command * * @var string */ - protected $signature = 'publish:404 + protected $signature = 'publish:404 {--type= : The view to publish. Must be Blade or Markdown } {--force : Overwrite existing files}'; @@ -42,7 +42,7 @@ public function handle() $this->error('Type `'.$type.'` is not valid. It must be either `blade` or `markdown`'); return 400; } - + if ($type === 'blade') { $source = Hyde::path('src/resources/stubs/404.blade.php'); $path = Hyde::path('resources/views/pages/404.blade.php'); diff --git a/app/Commands/Validate.php b/app/Commands/Validate.php index f77fb24..1f1cf1e 100644 --- a/app/Commands/Validate.php +++ b/app/Commands/Validate.php @@ -2,7 +2,7 @@ namespace App\Commands; -use App\Hyde\Hyde; +use App\Core\Hyde; use LaravelZero\Framework\Commands\Command; class Validate extends Command diff --git a/app/Core/Actions/ConvertsArrayToFrontMatter.php b/app/Core/Actions/ConvertsArrayToFrontMatter.php index e593846..1afa8ee 100644 --- a/app/Core/Actions/ConvertsArrayToFrontMatter.php +++ b/app/Core/Actions/ConvertsArrayToFrontMatter.php @@ -1,6 +1,6 @@ [ 'enabled' => true, 'markdown' => 'Site built with the Free and Open Source [HydePHP](https://github.com/hydephp/hyde). @@ -108,7 +108,7 @@ |-------------------------------------------------------------------------- | There may be pages you want to exclude from the automatic navigation menu, | such as error pages. Add their slugs here and they will not be included. - | + | */ 'navigationMenuBlacklist' => [ @@ -126,7 +126,7 @@ | can reorder the page slugs in the list and the links will be sorted | in that order. Link items without an entry here will have fall | back to the default priority of 999, putting them last. - | + | */ 'documentationPageOrder' => [ diff --git a/config/view.php b/config/view.php index 2ad680f..3060582 100644 --- a/config/view.php +++ b/config/view.php @@ -2,7 +2,7 @@ return [ 'paths' => [ - App\Hyde\Hyde::viewPath(), + App\Core\Hyde::viewPath(), ], 'compiled' => env( diff --git a/resources/views/components/docs/content.blade.php b/resources/views/components/docs/content.blade.php index ed26c05..7e0b5c3 100644 --- a/resources/views/components/docs/content.blade.php +++ b/resources/views/components/docs/content.blade.php @@ -1,5 +1,5 @@
    App\Hyde\Hyde::hasTorchlight()])> + @class(['mx-auto prose max-w-3xl', 'torchlight-enabled' => App\Core\Hyde::hasTorchlight()])>
    {!! $markdown !!}
    diff --git a/resources/views/components/docs/sidebar.blade.php b/resources/views/components/docs/sidebar.blade.php index de33dd3..0a60a80 100644 --- a/resources/views/components/docs/sidebar.blade.php +++ b/resources/views/components/docs/sidebar.blade.php @@ -1,7 +1,7 @@ @include('components.docs.sidebar-header')