diff --git a/config/hyde.php b/config/hyde.php index 7ca584b61c1..39124d290de 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -53,6 +53,7 @@ 'features' => [ // Page Modules + Features::htmlPages(), Features::blogPosts(), Features::bladePages(), Features::markdownPages(), diff --git a/packages/framework/config/hyde.php b/packages/framework/config/hyde.php index 7ca584b61c1..39124d290de 100644 --- a/packages/framework/config/hyde.php +++ b/packages/framework/config/hyde.php @@ -53,6 +53,7 @@ 'features' => [ // Page Modules + Features::htmlPages(), Features::blogPosts(), Features::bladePages(), Features::markdownPages(), diff --git a/packages/framework/src/Actions/SourceFileParser.php b/packages/framework/src/Actions/SourceFileParser.php index d12b09528c9..ddece7d77f1 100644 --- a/packages/framework/src/Actions/SourceFileParser.php +++ b/packages/framework/src/Actions/SourceFileParser.php @@ -33,6 +33,19 @@ public function __construct(string $pageClass, string $identifier) $this->page = $this->constructPage($pageClass); } + protected function constructPage(string $pageClass): HydePage|BladePage|BaseMarkdownPage + { + if ($pageClass === BladePage::class) { + return $this->parseBladePage(); + } + + if (is_subclass_of($pageClass, BaseMarkdownPage::class)) { + return $this->parseMarkdownPage($pageClass); + } + + return new $pageClass($this->identifier); + } + protected function parseBladePage(): BladePage { return new BladePage( @@ -59,13 +72,4 @@ public function get(): HydePage { return $this->page; } - - protected function constructPage(string $pageClass): BladePage|BaseMarkdownPage - { - if ($pageClass === BladePage::class) { - return $this->parseBladePage(); - } - - return $this->parseMarkdownPage($pageClass); - } } diff --git a/packages/framework/src/Foundation/FileCollection.php b/packages/framework/src/Foundation/FileCollection.php index c6621e062ef..2d4dfbaa3fd 100644 --- a/packages/framework/src/Foundation/FileCollection.php +++ b/packages/framework/src/Foundation/FileCollection.php @@ -8,6 +8,7 @@ use Hyde\Framework\Models\File; use Hyde\Framework\Models\Pages\BladePage; use Hyde\Framework\Models\Pages\DocumentationPage; +use Hyde\Framework\Models\Pages\HtmlPage; use Hyde\Framework\Models\Pages\MarkdownPage; use Hyde\Framework\Models\Pages\MarkdownPost; use Hyde\Framework\Services\DiscoveryService; @@ -45,6 +46,10 @@ public function getMediaFiles(): self protected function runDiscovery(): self { + if (Features::hasHtmlPages()) { + $this->discoverFilesFor(HtmlPage::class); + } + if (Features::hasBladePages()) { $this->discoverFilesFor(BladePage::class); } diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 658a57dc33f..0b74c59e198 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -8,6 +8,7 @@ use Hyde\Framework\Helpers\Features; use Hyde\Framework\Models\Pages\BladePage; use Hyde\Framework\Models\Pages\DocumentationPage; +use Hyde\Framework\Models\Pages\HtmlPage; use Hyde\Framework\Models\Pages\MarkdownPage; use Hyde\Framework\Models\Pages\MarkdownPost; use Illuminate\Support\Collection; @@ -32,6 +33,10 @@ public function getPages(?string $pageClass = null): self protected function runDiscovery(): self { + if (Features::hasHtmlPages()) { + $this->discoverPagesFor(HtmlPage::class); + } + if (Features::hasBladePages()) { $this->discoverPagesFor(BladePage::class); } diff --git a/packages/framework/src/Helpers/Features.php b/packages/framework/src/Helpers/Features.php index bf55c5db365..86ec1a81266 100644 --- a/packages/framework/src/Helpers/Features.php +++ b/packages/framework/src/Helpers/Features.php @@ -30,6 +30,7 @@ public static function enabled(string $feature): bool { return in_array($feature, config('hyde.features', [ // Page Modules + static::htmlPages(), static::blogPosts(), static::bladePages(), static::markdownPages(), @@ -54,6 +55,11 @@ public static function hasBlogPosts(): bool return static::enabled(static::blogPosts()); } + public static function hasHtmlPages(): bool + { + return static::enabled(static::htmlPages()); + } + public static function hasBladePages(): bool { return static::enabled(static::bladePages()); @@ -106,6 +112,11 @@ public static function blogPosts(): string return 'blog-posts'; } + public static function htmlPages(): string + { + return 'html-pages'; + } + public static function bladePages(): string { return 'blade-pages'; diff --git a/packages/framework/src/Models/Pages/HtmlPage.php b/packages/framework/src/Models/Pages/HtmlPage.php new file mode 100644 index 00000000000..95aca12be98 --- /dev/null +++ b/packages/framework/src/Models/Pages/HtmlPage.php @@ -0,0 +1,22 @@ +getSourcePath()); + } + + public function compile(): string + { + return $this->contents(); + } +} diff --git a/packages/framework/tests/Feature/HtmlPageTest.php b/packages/framework/tests/Feature/HtmlPageTest.php new file mode 100644 index 00000000000..a828e7b2fa6 --- /dev/null +++ b/packages/framework/tests/Feature/HtmlPageTest.php @@ -0,0 +1,30 @@ +file(HtmlPage::$sourceDirectory.'/foo.html', 'bar'); + + $page = new HtmlPage('foo'); + + $this->assertEquals('bar', $page->compile()); + } + + public function testCompileMethodUsesContents() + { + $this->file(HtmlPage::$sourceDirectory.'/foo.html', 'bar'); + + $page = new HtmlPage('foo'); + + $this->assertSame($page->contents(), $page->compile()); + } +} diff --git a/packages/framework/tests/Feature/SourceFileParserTest.php b/packages/framework/tests/Feature/SourceFileParserTest.php index 7a3c569c402..ef5b0538b31 100644 --- a/packages/framework/tests/Feature/SourceFileParserTest.php +++ b/packages/framework/tests/Feature/SourceFileParserTest.php @@ -5,6 +5,7 @@ use Hyde\Framework\Actions\SourceFileParser; use Hyde\Framework\Models\Pages\BladePage; use Hyde\Framework\Models\Pages\DocumentationPage; +use Hyde\Framework\Models\Pages\HtmlPage; use Hyde\Framework\Models\Pages\MarkdownPage; use Hyde\Framework\Models\Pages\MarkdownPost; use Hyde\Testing\TestCase; @@ -60,6 +61,17 @@ public function test_documentation_page_parser() $this->assertEquals('Foo Bar Baz', $page->title); } + public function test_html_page_parser() + { + $this->file('_pages/foo.html', '

Foo Bar

'); + + $parser = new SourceFileParser(HtmlPage::class, 'foo'); + $page = $parser->get(); + $this->assertInstanceOf(HtmlPage::class, $page); + $this->assertEquals('foo', $page->identifier); + $this->assertEquals('

Foo Bar

', $page->contents()); + } + public function test_parsed_page_is_run_through_dynamic_constructor() { $this->markdown('_pages/foo.md', '# Foo Bar', ['title' => 'Foo Bar Baz']); diff --git a/packages/framework/tests/Feature/StaticPageBuilderTest.php b/packages/framework/tests/Feature/StaticPageBuilderTest.php index 1ba80c51fd4..6af4281c2fa 100644 --- a/packages/framework/tests/Feature/StaticPageBuilderTest.php +++ b/packages/framework/tests/Feature/StaticPageBuilderTest.php @@ -7,6 +7,7 @@ use Hyde\Framework\HydeServiceProvider; use Hyde\Framework\Models\Pages\BladePage; use Hyde\Framework\Models\Pages\DocumentationPage; +use Hyde\Framework\Models\Pages\HtmlPage; use Hyde\Framework\Models\Pages\MarkdownPage; use Hyde\Framework\Models\Pages\MarkdownPost; use Hyde\Testing\TestCase; @@ -95,6 +96,34 @@ public function test_can_build_documentation_page() $this->validateBasicHtml(file_get_contents(Hyde::path('_site/'.'docs/foo.html'))); } + public function test_can_build_html_page() + { + $this->file('_pages/foo.html', 'bar'); + $page = new HtmlPage('foo'); + + new StaticPageBuilder($page, true); + + $this->assertFileExists(Hyde::path('_site/foo.html')); + $this->assertStringEqualsFile(Hyde::path('_site/foo.html'), 'bar'); + unlink(Hyde::path('_site/foo.html')); + } + + public function test_can_build_nested_html_page() + { + mkdir(Hyde::path('_pages/foo')); + file_put_contents(Hyde::path('_pages/foo/bar.html'), 'baz'); + $page = new HtmlPage('foo/bar'); + + new StaticPageBuilder($page, true); + + $this->assertFileExists(Hyde::path('_site/foo/bar.html')); + $this->assertStringEqualsFile(Hyde::path('_site/foo/bar.html'), 'baz'); + + unlink(Hyde::path('_site/foo/bar.html')); + unlink(Hyde::path('_pages/foo/bar.html')); + rmdir(Hyde::path('_pages/foo')); + } + public function test_creates_custom_documentation_directory() { $page = DocumentationPage::make('foo'); diff --git a/packages/framework/tests/Feature/StaticSiteServiceTest.php b/packages/framework/tests/Feature/StaticSiteServiceTest.php index 4a14d44c8ee..ca654fc119b 100644 --- a/packages/framework/tests/Feature/StaticSiteServiceTest.php +++ b/packages/framework/tests/Feature/StaticSiteServiceTest.php @@ -56,6 +56,30 @@ public function test_build_command_transfers_media_asset_files() unlink(Hyde::path('_site/media/test-image.png')); } + public function test_all_page_types_can_be_compiled() + { + $this->file('_pages/html.html'); + $this->file('_pages/blade.blade.php'); + $this->file('_pages/markdown.md'); + $this->file('_posts/post.md'); + $this->file('_docs/docs.md'); + + $this->artisan('build') + ->assertExitCode(0); + + $this->assertFileExists(Hyde::path('_site/html.html')); + $this->assertFileExists(Hyde::path('_site/blade.html')); + $this->assertFileExists(Hyde::path('_site/markdown.html')); + $this->assertFileExists(Hyde::path('_site/posts/post.html')); + $this->assertFileExists(Hyde::path('_site/docs/docs.html')); + + unlink(Hyde::path('_site/html.html')); + unlink(Hyde::path('_site/blade.html')); + unlink(Hyde::path('_site/markdown.html')); + unlink(Hyde::path('_site/posts/post.html')); + unlink(Hyde::path('_site/docs/docs.html')); + } + public function test_print_initial_information_allows_api_to_be_disabled() { $this->artisan('build --no-api')