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', '