From d52c9966bcf67d985c77752cbec8b4872f1b31cb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 15:50:10 +0100 Subject: [PATCH 0001/2811] [2.x] Set up HydePHP v2 --- RELEASE_NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 0624889cb02..1fd59536328 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,4 +1,4 @@ -## [Unreleased] - YYYY-MM-DD +## [v2-dev] - YYYY-MM-DD ### About From cd0b22753dd991e1a6853355b1cfb682d8abdc25 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 16:01:53 +0100 Subject: [PATCH 0002/2811] Reset release notes --- RELEASE_NOTES.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 1fd59536328..3f1a32d1613 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -10,10 +10,10 @@ This serves two purposes: 2. At release time, you can move the Unreleased section changes into a new release version section. ### Added -- Added info banners when dashboard content sections are empty in https://github.com/hydephp/develop/pull/1494 +- for new features. ### Changed -- Shortened the path printed to console when using the dashboard to create a page in https://github.com/hydephp/develop/pull/1492 +- for changes in existing functionality. ### Deprecated - for soon-to-be removed features. @@ -22,8 +22,7 @@ This serves two purposes: - for now removed features. ### Fixed -- Improved support for running HydePHP through the Phar archive in https://github.com/hydephp/develop/pull/1491 -- Fixed wrong section title in the dashboard page in https://github.com/hydephp/develop/pull/1493 +- for any bug fixes. ### Security - in case of vulnerabilities. From 4e3a0c2a1ea3924923b8e5c6b519647fee075130 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 15:57:53 +0100 Subject: [PATCH 0003/2811] Deprecate GenerateSearch.php --- RELEASE_NOTES.md | 2 +- .../src/Framework/Actions/PostBuildTasks/GenerateSearch.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 3f1a32d1613..9e868506daa 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -16,7 +16,7 @@ This serves two purposes: - for changes in existing functionality. ### Deprecated -- for soon-to-be removed features. +- \Hyde\Framework\Actions\PostBuildTasks\GenerateSearch ### Removed - for now removed features. diff --git a/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSearch.php b/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSearch.php index 991190ff4b2..a2d115a6e96 100644 --- a/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSearch.php +++ b/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSearch.php @@ -9,6 +9,7 @@ use Hyde\Framework\Features\Documentation\DocumentationSearchPage; use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; +/** @deprecated */ class GenerateSearch extends PostBuildTask { use InteractsWithDirectories; From d9eec2881648aab1742a18689257daf20668d79c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 16:11:45 +0100 Subject: [PATCH 0004/2811] Add new internal `GeneratesDocumentationSearchIndex::generate` method --- .../Actions/GeneratesDocumentationSearchIndex.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php index 1e0948e47cf..5e5882bf234 100644 --- a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php @@ -39,6 +39,17 @@ public static function handle(): string return $service->path; } + /** + * Generate the search index return it as a string. + */ + public static function generate(): string + { + $service = new static(); + $service->run(); + + return $service->index->toJson(); + } + protected function __construct() { $this->index = new Collection(); From feb99e9d681f802554e38a9235f856cdc651de63 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 15:59:24 +0100 Subject: [PATCH 0005/2811] Deprecate internal `GeneratesDocumentationSearchIndex::handle` method --- .../src/Framework/Actions/GeneratesDocumentationSearchIndex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php index 5e5882bf234..85e17aa1448 100644 --- a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php @@ -26,7 +26,7 @@ class GeneratesDocumentationSearchIndex protected string $path; /** - * Generate the search index and save it to disk. + * @deprecated Generate the search index and save it to disk. * * @return string The path to the generated file. */ From 697e016fb300334e602576084775d28fd5b81d59 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 16:10:43 +0100 Subject: [PATCH 0006/2811] Add experimental `InMemoryPage::getOutputPath` overload support --- RELEASE_NOTES.md | 2 +- packages/framework/src/Pages/InMemoryPage.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 9e868506daa..18fd270e216 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -10,7 +10,7 @@ This serves two purposes: 2. At release time, you can move the Unreleased section changes into a new release version section. ### Added -- for new features. +- Add experimental InMemoryPage::getOutputPath overload support ### Changed - for changes in existing functionality. diff --git a/packages/framework/src/Pages/InMemoryPage.php b/packages/framework/src/Pages/InMemoryPage.php index 541e9356ec9..56a429344e2 100644 --- a/packages/framework/src/Pages/InMemoryPage.php +++ b/packages/framework/src/Pages/InMemoryPage.php @@ -82,6 +82,16 @@ public function getBladeView(): string return $this->view; } + /** @experimental Get the path to the output file for the page. */ + public function getOutputPath(): string + { + if ($this->hasMacro('getOutputPath')) { + return $this->__call('getOutputPath', []); + } + + return parent::getOutputPath(); + } + /** * Get the contents that will be saved to disk for this page. * From d48918410f17c4ab6ede24d254d94fb58f228912 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 16:22:32 +0100 Subject: [PATCH 0007/2811] Add upgrade guide section --- RELEASE_NOTES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 3f1a32d1613..f5a0bd794e1 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -26,3 +26,7 @@ This serves two purposes: ### Security - in case of vulnerabilities. + +### Upgrade Guide + +If there are any breaking changes, include an upgrade guide here. From 9bee9cd05ac3b1efb8eef8236b51804a5c6c5413 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 16:23:19 +0100 Subject: [PATCH 0008/2811] Update build task service to not call deprecated search generator --- .../framework/src/Framework/Services/BuildTaskService.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/framework/src/Framework/Services/BuildTaskService.php b/packages/framework/src/Framework/Services/BuildTaskService.php index a976526e214..d2eb432a015 100644 --- a/packages/framework/src/Framework/Services/BuildTaskService.php +++ b/packages/framework/src/Framework/Services/BuildTaskService.php @@ -11,7 +11,6 @@ use Hyde\Framework\Features\BuildTasks\PreBuildTask; use Hyde\Framework\Features\BuildTasks\PostBuildTask; use Hyde\Framework\Actions\PreBuildTasks\CleanSiteDirectory; -use Hyde\Framework\Actions\PostBuildTasks\GenerateSearch; use Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed; use Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap; use Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest; @@ -136,7 +135,6 @@ private function registerFrameworkTasks(): void $this->registerIf(GenerateBuildManifest::class, $this->canGenerateManifest()); $this->registerIf(GenerateSitemap::class, $this->canGenerateSitemap()); $this->registerIf(GenerateRssFeed::class, $this->canGenerateFeed()); - $this->registerIf(GenerateSearch::class, $this->canGenerateSearch()); } private function canCleanSiteDirectory(): bool @@ -158,9 +156,4 @@ private function canGenerateFeed(): bool { return Features::rss(); } - - private function canGenerateSearch(): bool - { - return Features::hasDocumentationSearch(); - } } From c8937ad292344fc3bbb68adb9793627dbf343918 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 16:38:24 +0100 Subject: [PATCH 0009/2811] Update core extension to add search index as an in memory page --- .../src/Foundation/HydeCoreExtension.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/framework/src/Foundation/HydeCoreExtension.php b/packages/framework/src/Foundation/HydeCoreExtension.php index 6c48936a370..95f1963bfad 100644 --- a/packages/framework/src/Foundation/HydeCoreExtension.php +++ b/packages/framework/src/Foundation/HydeCoreExtension.php @@ -8,9 +8,12 @@ use Hyde\Pages\BladePage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; +use Hyde\Pages\InMemoryPage; use Hyde\Pages\DocumentationPage; +use Hyde\Foundation\Kernel\PageCollection; use Hyde\Foundation\Concerns\HydeExtension; use Hyde\Facades\Features; +use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; use function array_filter; use function array_keys; @@ -28,4 +31,18 @@ public static function getPageClasses(): array DocumentationPage::class => Features::hasDocumentationPages(), ], fn (bool $value): bool => $value)); } + + public function discoverPages(PageCollection $collection): void + { + if (Features::hasDocumentationSearch()) { + $collection->addPage(tap(new InMemoryPage('search.json'), function (InMemoryPage $page): void { + $page->macro('compile', function (): string { + return GeneratesDocumentationSearchIndex::generate(); + }); + $page->macro('getOutputPath', function (): string { + return DocumentationPage::outputDirectory().'/search.json'; + }); + })); + } + } } From 30f3ce6b809ede0b93b4007af67a6dc219eea681 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 17:00:56 +0100 Subject: [PATCH 0010/2811] Update core extension to inject search page during discovery --- packages/framework/src/Foundation/HydeCoreExtension.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Foundation/HydeCoreExtension.php b/packages/framework/src/Foundation/HydeCoreExtension.php index 95f1963bfad..4f1784d1b8a 100644 --- a/packages/framework/src/Foundation/HydeCoreExtension.php +++ b/packages/framework/src/Foundation/HydeCoreExtension.php @@ -14,6 +14,7 @@ use Hyde\Foundation\Concerns\HydeExtension; use Hyde\Facades\Features; use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; +use Hyde\Framework\Features\Documentation\DocumentationSearchPage; use function array_filter; use function array_keys; @@ -43,6 +44,10 @@ public function discoverPages(PageCollection $collection): void return DocumentationPage::outputDirectory().'/search.json'; }); })); + + if (DocumentationSearchPage::enabled()) { + $collection->addPage(new DocumentationSearchPage()); + } } } } From 733b95f5995d43c5e01c5fda97019d29b6474df5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 17:06:34 +0100 Subject: [PATCH 0011/2811] Hide dynamic search pages from navigation --- packages/framework/src/Foundation/HydeCoreExtension.php | 2 +- .../Features/Documentation/DocumentationSearchPage.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/HydeCoreExtension.php b/packages/framework/src/Foundation/HydeCoreExtension.php index 4f1784d1b8a..27c0706a93c 100644 --- a/packages/framework/src/Foundation/HydeCoreExtension.php +++ b/packages/framework/src/Foundation/HydeCoreExtension.php @@ -36,7 +36,7 @@ public static function getPageClasses(): array public function discoverPages(PageCollection $collection): void { if (Features::hasDocumentationSearch()) { - $collection->addPage(tap(new InMemoryPage('search.json'), function (InMemoryPage $page): void { + $collection->addPage(tap(new InMemoryPage('search.json', ['navigation' => ['hidden' => true]]), function (InMemoryPage $page): void { $page->macro('compile', function (): string { return GeneratesDocumentationSearchIndex::generate(); }); diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index 4563eb45337..f58ff0b83ca 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -36,6 +36,7 @@ public function __construct() { parent::__construct('search', [ 'title' => 'Search', + 'navigation' => ['hidden' => true], ]); } From 8bfe35ea59f0463ed0d585d77c0d74d13ac3a177 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 17:54:55 +0100 Subject: [PATCH 0012/2811] Run tests without documentation search feature --- .../tests/Feature/PageCollectionTest.php | 10 +++++++++ .../tests/Feature/RouteCollectionTest.php | 4 ++++ .../Unit/Pages/PageModelGetHelperTest.php | 4 ++++ packages/testing/src/ResetsApplication.php | 22 +++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 19a961b761d..f055ae3bf24 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -80,6 +80,7 @@ public function test_get_page_returns_parsed_page_object_for_given_source_path() public function test_get_pages_returns_collection_of_pages_of_given_class() { $this->withoutDefaultPages(); + $this->withoutDocumentationSearch(); $this->file('_pages/foo.blade.php'); $this->file('_pages/foo.md'); @@ -103,11 +104,13 @@ public function test_get_pages_returns_collection_of_pages_of_given_class() $this->assertEquals(new HtmlPage('foo'), Pages::getPages(HtmlPage::class)->first()); $this->restoreDefaultPages(); + $this->restoreDocumentationSearch(); } public function test_get_pages_returns_all_pages_when_not_supplied_with_class_string() { $this->withoutDefaultPages(); + $this->withoutDocumentationSearch(); $this->file('_pages/foo.blade.php'); $this->file('_pages/foo.md'); @@ -125,13 +128,16 @@ public function test_get_pages_returns_all_pages_when_not_supplied_with_class_st $this->assertEquals(new HtmlPage('foo'), $collection->get('_pages/foo.html')); $this->restoreDefaultPages(); + $this->restoreDocumentationSearch(); } public function test_get_pages_returns_empty_collection_when_no_pages_are_discovered() { $this->withoutDefaultPages(); + $this->withoutDocumentationSearch(); $this->assertEmpty(Pages::getPages()); $this->restoreDefaultPages(); + $this->restoreDocumentationSearch(); } public function test_pages_are_not_discovered_for_disabled_features() @@ -155,6 +161,8 @@ public function test_pages_are_not_discovered_for_disabled_features() public function test_pages_with_custom_source_directories_are_discovered_properly() { + $this->withoutDocumentationSearch(); + BladePage::setSourceDirectory('.source/pages'); MarkdownPage::setSourceDirectory('.source/pages'); MarkdownPost::setSourceDirectory('.source/posts'); @@ -177,6 +185,8 @@ public function test_pages_with_custom_source_directories_are_discovered_properl $this->assertEquals(new MarkdownPage('foo'), $collection->get('.source/pages/foo.md')); $this->assertEquals(new MarkdownPost('foo'), $collection->get('.source/posts/foo.md')); $this->assertEquals(new DocumentationPage('foo'), $collection->get('.source/docs/foo.md')); + + $this->restoreDocumentationSearch(); } public function test_get_file_throws_exception_when_file_is_not_found() diff --git a/packages/framework/tests/Feature/RouteCollectionTest.php b/packages/framework/tests/Feature/RouteCollectionTest.php index 383ef835a47..e1b8c74a0dd 100644 --- a/packages/framework/tests/Feature/RouteCollectionTest.php +++ b/packages/framework/tests/Feature/RouteCollectionTest.php @@ -40,6 +40,7 @@ public function test_boot_method_discovers_all_pages() public function test_boot_method_discovers_all_page_types() { $this->withoutDefaultPages(); + $this->withoutDocumentationSearch(); $this->file('_pages/blade.blade.php'); $this->file('_pages/markdown.md'); @@ -61,6 +62,7 @@ public function test_boot_method_discovers_all_page_types() ], $collection->all()); $this->restoreDefaultPages(); + $this->restoreDocumentationSearch(); } public function test_get_routes_returns_all_routes() @@ -77,6 +79,7 @@ public function test_get_routes_returns_all_routes() public function test_get_routes_for_model_returns_collection_of_routes_of_given_class() { $this->withoutDefaultPages(); + $this->withoutDocumentationSearch(); $this->file('_pages/blade.blade.php'); $this->file('_pages/markdown.md'); @@ -94,6 +97,7 @@ public function test_get_routes_for_model_returns_collection_of_routes_of_given_ $this->assertEquals(new Route(new HtmlPage('html')), Routes::getRoutes(HtmlPage::class)->first()); $this->restoreDefaultPages(); + $this->restoreDocumentationSearch(); } public function test_add_route_adds_new_route() diff --git a/packages/framework/tests/Unit/Pages/PageModelGetHelperTest.php b/packages/framework/tests/Unit/Pages/PageModelGetHelperTest.php index fea50135306..f8727b4caed 100644 --- a/packages/framework/tests/Unit/Pages/PageModelGetHelperTest.php +++ b/packages/framework/tests/Unit/Pages/PageModelGetHelperTest.php @@ -51,6 +51,8 @@ public function test_markdown_post_get_helper_returns_markdown_post_collection() public function test_documentation_page_get_helper_returns_documentation_page_collection() { + $this->withoutDocumentationSearch(); + Filesystem::touch('_docs/test-page.md'); $collection = DocumentationPage::all(); @@ -59,5 +61,7 @@ public function test_documentation_page_get_helper_returns_documentation_page_co $this->assertContainsOnlyInstancesOf(DocumentationPage::class, $collection); Filesystem::unlink('_docs/test-page.md'); + + $this->restoreDocumentationSearch(); } } diff --git a/packages/testing/src/ResetsApplication.php b/packages/testing/src/ResetsApplication.php index f5db985f41f..96729828402 100644 --- a/packages/testing/src/ResetsApplication.php +++ b/packages/testing/src/ResetsApplication.php @@ -50,6 +50,28 @@ protected function restoreDefaultPages(): void copy(Hyde::vendorPath('resources/views/pages/404.blade.php'), Hyde::path('_pages/404.blade.php')); } + /** @experimental We may want to make this a part of {@see static::withoutDefaultPages()} */ + protected function withoutDocumentationSearch(): void + { + $features = config('hyde.features'); + + $flipped = array_flip($features); + unset($flipped['documentation-search']); + $features = array_flip($flipped); + + config(['hyde.features' => $features]); + } + + /** @experimental We may want to make this a part of {@see static::restoreDefaultPages()} */ + protected function restoreDocumentationSearch(): void + { + $features = config('hyde.features'); + + $features[] = 'documentation-search'; + + config(['hyde.features' => $features]); + } + protected static function unlinkUnlessDefault(string $filepath): void { $protected = [ From f55ad51f56a502619e95a96996157ddf9dd590d1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 18:06:56 +0100 Subject: [PATCH 0013/2811] Hide the search page from sidebar generation Could cause issues if the user wants to document their search page, maybe we tie it into the create_search_page config option? Because if they have a custom search page, they would want to disable that feature, and then this should also be disabled. --- .../src/Framework/Actions/GeneratesDocumentationSearchIndex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php index 85e17aa1448..368895b599d 100644 --- a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php @@ -59,7 +59,7 @@ protected function __construct() protected function run(): void { DocumentationPage::all()->each(function (DocumentationPage $page): void { - if (! in_array($page->identifier, Config::getArray('docs.exclude_from_search', []))) { + if (! in_array($page->identifier, array_merge(Config::getArray('docs.exclude_from_search', []), ['search']))) { $this->index->push($this->generatePageEntry($page)); } }); From ba44d871ba03516d4ea0c0a5b06ac58397f7bcb3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 20:12:16 +0100 Subject: [PATCH 0014/2811] Test documentation search sitemap integration --- .../Feature/Services/SitemapServiceTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/framework/tests/Feature/Services/SitemapServiceTest.php b/packages/framework/tests/Feature/Services/SitemapServiceTest.php index e82342eb974..0c735f08819 100644 --- a/packages/framework/tests/Feature/Services/SitemapServiceTest.php +++ b/packages/framework/tests/Feature/Services/SitemapServiceTest.php @@ -67,6 +67,7 @@ public function test_generate_adds_markdown_posts_to_xml() public function test_generate_adds_documentation_pages_to_xml() { + $this->withoutDocumentationSearch(); Filesystem::touch('_docs/foo.md'); $service = new SitemapGenerator(); @@ -74,6 +75,19 @@ public function test_generate_adds_documentation_pages_to_xml() $this->assertCount(3, $service->getXmlElement()->url); + Filesystem::unlink('_docs/foo.md'); + $this->restoreDocumentationSearch(); + } + + public function test_generate_adds_documentation_search_pages_to_xml() + { + Filesystem::touch('_docs/foo.md'); + + $service = new SitemapGenerator(); + $service->generate(); + + $this->assertCount(5, $service->getXmlElement()->url); + Filesystem::unlink('_docs/foo.md'); } @@ -131,6 +145,7 @@ public function test_all_route_types_are_discovered() { config(['hyde.url' => 'foo']); Filesystem::unlink(['_pages/index.blade.php', '_pages/404.blade.php']); + $this->withoutDocumentationSearch(); $files = [ '_pages/blade.blade.php', @@ -157,6 +172,8 @@ public function test_all_route_types_are_discovered() copy(Hyde::vendorPath('resources/views/homepages/welcome.blade.php'), Hyde::path('_pages/index.blade.php')); copy(Hyde::vendorPath('resources/views/pages/404.blade.php'), Hyde::path('_pages/404.blade.php')); + + $this->restoreDocumentationSearch(); } public function testLinksFallbackToRelativeLinksWhenASiteUrlIsNotSet() From c45a64e6aabd3a037b028da05e39593c0cf9a963 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 20:29:02 +0100 Subject: [PATCH 0015/2811] Remove blanket assertion Was probably added as a blanket to include build task output. Can't find any info in the Git log. Since it's unclear, and removing it makes the test pass, that's exactly what I'm going to do. --- packages/framework/tests/Feature/StaticSiteServiceTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/tests/Feature/StaticSiteServiceTest.php b/packages/framework/tests/Feature/StaticSiteServiceTest.php index c4bc8d35dbf..165a11ad07b 100644 --- a/packages/framework/tests/Feature/StaticSiteServiceTest.php +++ b/packages/framework/tests/Feature/StaticSiteServiceTest.php @@ -83,7 +83,6 @@ public function test_all_page_types_can_be_compiled() ->expectsOutput('Creating Markdown Pages...') ->expectsOutput('Creating Markdown Posts...') ->expectsOutput('Creating Documentation Pages...') - ->doesntExpectOutputToContain('Creating') ->assertExitCode(0); $this->assertFileExists(Hyde::path('_site/html.html')); From 49de93d20f9d1f3594b889fecf7b378b1b3d3e73 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 16:58:36 +0100 Subject: [PATCH 0016/2811] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c5a5421e35c..afe7ac9692f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -13,7 +13,7 @@ This serves two purposes: - Add experimental InMemoryPage::getOutputPath overload support ### Changed -- for changes in existing functionality. +- Changed how the documentation search is generated, to be an InMemoryPage instead of a post-build task. ### Deprecated - \Hyde\Framework\Actions\PostBuildTasks\GenerateSearch @@ -30,3 +30,11 @@ This serves two purposes: ### Upgrade Guide If there are any breaking changes, include an upgrade guide here. + +#### Documentation search changes + +The documentation search page and search index have been changed to be generated as InMemoryPages instead of a post-build task. + +In case you have customized the GenerateSearch post-build task, you will need to adapt your code to the new InMemoryPage, which is generated in the HydeCoreExtension class. + +For more information, see https://github.com/hydephp/develop/pull/1498. From 5728f7ad29a4295d3fb003cdb533feaf6f199f17 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 10:38:23 +0100 Subject: [PATCH 0017/2811] Extract helper method --- .../Actions/GeneratesDocumentationSearchIndex.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php index 368895b599d..dfc7c4f95d8 100644 --- a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php @@ -59,7 +59,7 @@ protected function __construct() protected function run(): void { DocumentationPage::all()->each(function (DocumentationPage $page): void { - if (! in_array($page->identifier, array_merge(Config::getArray('docs.exclude_from_search', []), ['search']))) { + if (! in_array($page->identifier, $this->getPagesToExcludeFromSearch())) { $this->index->push($this->generatePageEntry($page)); } }); @@ -103,4 +103,9 @@ protected function getPath(): string { return Hyde::sitePath(DocumentationPage::outputDirectory().'/search.json'); } + + protected function getPagesToExcludeFromSearch(): array + { + return array_merge(Config::getArray('docs.exclude_from_search', []), ['search']); + } } From 3cb7f404f0b03f05b9ad6b02a14e959552741325 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 10:40:11 +0100 Subject: [PATCH 0018/2811] Make search index page exclusion dependent on config setting > Because if they have a custom search page, they would want to disable that feature, and then this should also be disabled. See https://github.com/hydephp/develop/pull/1498#discussion_r1425650912 --- .../src/Framework/Actions/GeneratesDocumentationSearchIndex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php index dfc7c4f95d8..64bbb7d8e67 100644 --- a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php @@ -106,6 +106,6 @@ protected function getPath(): string protected function getPagesToExcludeFromSearch(): array { - return array_merge(Config::getArray('docs.exclude_from_search', []), ['search']); + return array_merge(Config::getArray('docs.exclude_from_search', []), Config::getBool('docs.create_search_page', true) ? ['search'] : []); } } From bd140499e0d7850ca3e333eaddb9c9d45ba79a59 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 12:22:23 +0100 Subject: [PATCH 0019/2811] Extract experimental helper method Decoupling it from the extension cleans up the code, and allows us to use it in the build search command, even if it's not injected due to the search feature being disabled (then we still allow the user to force it like before) --- .../src/Foundation/HydeCoreExtension.php | 10 +--------- .../Actions/GeneratesDocumentationSearchIndex.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/framework/src/Foundation/HydeCoreExtension.php b/packages/framework/src/Foundation/HydeCoreExtension.php index 27c0706a93c..50d5d40a0ed 100644 --- a/packages/framework/src/Foundation/HydeCoreExtension.php +++ b/packages/framework/src/Foundation/HydeCoreExtension.php @@ -8,7 +8,6 @@ use Hyde\Pages\BladePage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; -use Hyde\Pages\InMemoryPage; use Hyde\Pages\DocumentationPage; use Hyde\Foundation\Kernel\PageCollection; use Hyde\Foundation\Concerns\HydeExtension; @@ -36,14 +35,7 @@ public static function getPageClasses(): array public function discoverPages(PageCollection $collection): void { if (Features::hasDocumentationSearch()) { - $collection->addPage(tap(new InMemoryPage('search.json', ['navigation' => ['hidden' => true]]), function (InMemoryPage $page): void { - $page->macro('compile', function (): string { - return GeneratesDocumentationSearchIndex::generate(); - }); - $page->macro('getOutputPath', function (): string { - return DocumentationPage::outputDirectory().'/search.json'; - }); - })); + $collection->addPage(GeneratesDocumentationSearchIndex::makePage()); if (DocumentationSearchPage::enabled()) { $collection->addPage(new DocumentationSearchPage()); diff --git a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php index 64bbb7d8e67..125f6098316 100644 --- a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php @@ -7,10 +7,12 @@ use Hyde\Hyde; use Hyde\Facades\Config; use Hyde\Facades\Filesystem; +use Hyde\Pages\InMemoryPage; use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Pages\DocumentationPage; use Illuminate\Support\Collection; +use function tap; use function basename; use function in_array; use function trim; @@ -50,6 +52,19 @@ public static function generate(): string return $service->index->toJson(); } + /** @experimental May be moved to a DocumentationSearch class */ + public static function makePage(): InMemoryPage + { + return tap(new InMemoryPage('search.json', ['navigation' => ['hidden' => true]]), function (InMemoryPage $page): void { + $page->macro('compile', function (): string { + return GeneratesDocumentationSearchIndex::generate(); + }); + $page->macro('getOutputPath', function (): string { + return DocumentationPage::outputDirectory().'/search.json'; + }); + }); + } + protected function __construct() { $this->index = new Collection(); From 158c6f223d736ee2af2b26afb22614bd5fb30485 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 15:51:35 +0100 Subject: [PATCH 0020/2811] Update build search command to use new search page system --- .../src/Console/Commands/BuildSearchCommand.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSearchCommand.php b/packages/framework/src/Console/Commands/BuildSearchCommand.php index 03cf8f95934..594fc5c3917 100644 --- a/packages/framework/src/Console/Commands/BuildSearchCommand.php +++ b/packages/framework/src/Console/Commands/BuildSearchCommand.php @@ -4,8 +4,10 @@ namespace Hyde\Console\Commands; -use Hyde\Framework\Actions\PostBuildTasks\GenerateSearch; use LaravelZero\Framework\Commands\Command; +use Hyde\Framework\Actions\StaticPageBuilder; +use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; +use Hyde\Framework\Features\Documentation\DocumentationSearchPage; /** * Run the build process for the documentation search index. @@ -20,6 +22,12 @@ class BuildSearchCommand extends Command public function handle(): int { - return (new GenerateSearch())->run($this->output); + StaticPageBuilder::handle(GeneratesDocumentationSearchIndex::makePage()); + + if (DocumentationSearchPage::enabled()) { + DocumentationSearchPage::generate(); + } + + return Command::SUCCESS; } } From 873b928714cb3b123df794a40c2ee9300f264355 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 15:52:46 +0100 Subject: [PATCH 0021/2811] Support getting the search page from the kernel In case it's been modified or injected somehow, this is a nicety to have --- .../src/Console/Commands/BuildSearchCommand.php | 16 ++++++++++++++-- .../Feature/Commands/BuildSearchCommandTest.php | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSearchCommand.php b/packages/framework/src/Console/Commands/BuildSearchCommand.php index 594fc5c3917..225980b2689 100644 --- a/packages/framework/src/Console/Commands/BuildSearchCommand.php +++ b/packages/framework/src/Console/Commands/BuildSearchCommand.php @@ -4,8 +4,11 @@ namespace Hyde\Console\Commands; -use LaravelZero\Framework\Commands\Command; +use Hyde\Pages\Concerns\HydePage; +use Hyde\Foundation\Facades\Pages; use Hyde\Framework\Actions\StaticPageBuilder; +use Hyde\Framework\Exceptions\FileNotFoundException; +use LaravelZero\Framework\Commands\Command; use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; use Hyde\Framework\Features\Documentation\DocumentationSearchPage; @@ -22,7 +25,7 @@ class BuildSearchCommand extends Command public function handle(): int { - StaticPageBuilder::handle(GeneratesDocumentationSearchIndex::makePage()); + StaticPageBuilder::handle($this->getPageFromKernel() ?? GeneratesDocumentationSearchIndex::makePage()); if (DocumentationSearchPage::enabled()) { DocumentationSearchPage::generate(); @@ -30,4 +33,13 @@ public function handle(): int return Command::SUCCESS; } + + protected function getPageFromKernel(): ?HydePage + { + try { + return Pages::getPage('search.json'); + } catch (FileNotFoundException) { + return null; + } + } } diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index d8dc55a2826..bd25e01bd78 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -6,8 +6,10 @@ use Hyde\Facades\Filesystem; use Hyde\Hyde; +use Hyde\Pages\InMemoryPage; use Hyde\Pages\DocumentationPage; use Hyde\Testing\TestCase; +use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; /** * @covers \Hyde\Console\Commands\BuildSearchCommand @@ -103,4 +105,18 @@ public function test_search_files_can_be_generated_for_custom_site_and_nested_do Filesystem::deleteDirectory('foo'); } + + public function test_command_uses_page_from_kernel_when_present() + { + Hyde::pages()->addPage(tap(GeneratesDocumentationSearchIndex::makePage(), function (InMemoryPage $page): void { + $page->macro('compile', fn () => '{"foo":"bar"}'); + })); + + $this->artisan('build:search')->assertExitCode(0); + $this->assertFileExists(Hyde::path('_site/docs/search.json')); + $this->assertSame('{"foo":"bar"}', Filesystem::getContents('_site/docs/search.json')); + + Filesystem::unlink('_site/docs/search.json'); + Filesystem::unlink('_site/docs/search.html'); + } } From 4f91f82c9a841889039ad2f5638610348ca2b644 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 17:11:10 +0100 Subject: [PATCH 0022/2811] Simplify logic to use nullable helper --- .../framework/src/Console/Commands/BuildSearchCommand.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSearchCommand.php b/packages/framework/src/Console/Commands/BuildSearchCommand.php index 225980b2689..21992b51668 100644 --- a/packages/framework/src/Console/Commands/BuildSearchCommand.php +++ b/packages/framework/src/Console/Commands/BuildSearchCommand.php @@ -7,7 +7,6 @@ use Hyde\Pages\Concerns\HydePage; use Hyde\Foundation\Facades\Pages; use Hyde\Framework\Actions\StaticPageBuilder; -use Hyde\Framework\Exceptions\FileNotFoundException; use LaravelZero\Framework\Commands\Command; use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; use Hyde\Framework\Features\Documentation\DocumentationSearchPage; @@ -36,10 +35,6 @@ public function handle(): int protected function getPageFromKernel(): ?HydePage { - try { - return Pages::getPage('search.json'); - } catch (FileNotFoundException) { - return null; - } + return Pages::get('search.json'); } } From e80cbb2f495dabf51435edfb3bf962b997c37a54 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 17:11:26 +0100 Subject: [PATCH 0023/2811] Inline simplified helper method --- .../framework/src/Console/Commands/BuildSearchCommand.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSearchCommand.php b/packages/framework/src/Console/Commands/BuildSearchCommand.php index 21992b51668..a0248172a17 100644 --- a/packages/framework/src/Console/Commands/BuildSearchCommand.php +++ b/packages/framework/src/Console/Commands/BuildSearchCommand.php @@ -4,7 +4,6 @@ namespace Hyde\Console\Commands; -use Hyde\Pages\Concerns\HydePage; use Hyde\Foundation\Facades\Pages; use Hyde\Framework\Actions\StaticPageBuilder; use LaravelZero\Framework\Commands\Command; @@ -24,7 +23,7 @@ class BuildSearchCommand extends Command public function handle(): int { - StaticPageBuilder::handle($this->getPageFromKernel() ?? GeneratesDocumentationSearchIndex::makePage()); + StaticPageBuilder::handle(Pages::get('search.json') ?? GeneratesDocumentationSearchIndex::makePage()); if (DocumentationSearchPage::enabled()) { DocumentationSearchPage::generate(); @@ -32,9 +31,4 @@ public function handle(): int return Command::SUCCESS; } - - protected function getPageFromKernel(): ?HydePage - { - return Pages::get('search.json'); - } } From 03f7fd897735c097bffb7b3cd27da505059c8680 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 17:15:54 +0100 Subject: [PATCH 0024/2811] Get the search page from the kernel as well --- .../framework/src/Console/Commands/BuildSearchCommand.php | 2 +- .../tests/Feature/Commands/BuildSearchCommandTest.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSearchCommand.php b/packages/framework/src/Console/Commands/BuildSearchCommand.php index a0248172a17..563778da0b1 100644 --- a/packages/framework/src/Console/Commands/BuildSearchCommand.php +++ b/packages/framework/src/Console/Commands/BuildSearchCommand.php @@ -26,7 +26,7 @@ public function handle(): int StaticPageBuilder::handle(Pages::get('search.json') ?? GeneratesDocumentationSearchIndex::makePage()); if (DocumentationSearchPage::enabled()) { - DocumentationSearchPage::generate(); + StaticPageBuilder::handle(Pages::get('docs/search') ?? new DocumentationSearchPage()); } return Command::SUCCESS; diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index bd25e01bd78..72a5f591930 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -106,15 +106,21 @@ public function test_search_files_can_be_generated_for_custom_site_and_nested_do Filesystem::deleteDirectory('foo'); } - public function test_command_uses_page_from_kernel_when_present() + public function test_command_uses_search_pages_from_kernel_when_present() { Hyde::pages()->addPage(tap(GeneratesDocumentationSearchIndex::makePage(), function (InMemoryPage $page): void { $page->macro('compile', fn () => '{"foo":"bar"}'); })); + Hyde::pages()->addPage(tap(new InMemoryPage('docs/search'), function (InMemoryPage $page): void { + $page->macro('compile', fn () => 'Foo'); + })); + $this->artisan('build:search')->assertExitCode(0); $this->assertFileExists(Hyde::path('_site/docs/search.json')); + $this->assertFileExists(Hyde::path('_site/docs/search.html')); $this->assertSame('{"foo":"bar"}', Filesystem::getContents('_site/docs/search.json')); + $this->assertSame('Foo', Filesystem::getContents('_site/docs/search.html')); Filesystem::unlink('_site/docs/search.json'); Filesystem::unlink('_site/docs/search.html'); From b021766d2f16be15a6c988e8b2b17e45384f2a22 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 17:17:42 +0100 Subject: [PATCH 0025/2811] Clean up test method --- .../framework/tests/Feature/Commands/BuildSearchCommandTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index 72a5f591930..2c289a5b4f9 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -117,8 +117,10 @@ public function test_command_uses_search_pages_from_kernel_when_present() })); $this->artisan('build:search')->assertExitCode(0); + $this->assertFileExists(Hyde::path('_site/docs/search.json')); $this->assertFileExists(Hyde::path('_site/docs/search.html')); + $this->assertSame('{"foo":"bar"}', Filesystem::getContents('_site/docs/search.json')); $this->assertSame('Foo', Filesystem::getContents('_site/docs/search.html')); From 799d51f4a9b164ff5f3bdd6d64559d7b2d6ae034 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 18:17:06 +0100 Subject: [PATCH 0026/2811] Extract a model class for the documentation search index --- .../GeneratesDocumentationSearchIndex.php | 11 +---- .../DocumentationSearchIndex.php | 46 +++++++++++++++++++ .../Commands/BuildSearchCommandTest.php | 4 +- 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php diff --git a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php index 125f6098316..e76c20496dd 100644 --- a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php @@ -11,8 +11,8 @@ use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Pages\DocumentationPage; use Illuminate\Support\Collection; +use Hyde\Framework\Features\Documentation\DocumentationSearchIndex; -use function tap; use function basename; use function in_array; use function trim; @@ -55,14 +55,7 @@ public static function generate(): string /** @experimental May be moved to a DocumentationSearch class */ public static function makePage(): InMemoryPage { - return tap(new InMemoryPage('search.json', ['navigation' => ['hidden' => true]]), function (InMemoryPage $page): void { - $page->macro('compile', function (): string { - return GeneratesDocumentationSearchIndex::generate(); - }); - $page->macro('getOutputPath', function (): string { - return DocumentationPage::outputDirectory().'/search.json'; - }); - }); + return DocumentationSearchIndex::make(); } protected function __construct() diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php new file mode 100644 index 00000000000..b5b650c722f --- /dev/null +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php @@ -0,0 +1,46 @@ + ['hidden' => true], + ]); + } + + public function compile(): string + { + return GeneratesDocumentationSearchIndex::generate(); + } + + public function getOutputPath(): string + { + return DocumentationPage::outputDirectory().'/search.json'; + } +} diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index 2c289a5b4f9..454b63196d3 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -9,7 +9,6 @@ use Hyde\Pages\InMemoryPage; use Hyde\Pages\DocumentationPage; use Hyde\Testing\TestCase; -use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; /** * @covers \Hyde\Console\Commands\BuildSearchCommand @@ -108,8 +107,9 @@ public function test_search_files_can_be_generated_for_custom_site_and_nested_do public function test_command_uses_search_pages_from_kernel_when_present() { - Hyde::pages()->addPage(tap(GeneratesDocumentationSearchIndex::makePage(), function (InMemoryPage $page): void { + Hyde::pages()->addPage(tap(new InMemoryPage('search.json'), function (InMemoryPage $page): void { $page->macro('compile', fn () => '{"foo":"bar"}'); + $page->macro('getOutputPath', fn () => 'docs/search.json'); })); Hyde::pages()->addPage(tap(new InMemoryPage('docs/search'), function (InMemoryPage $page): void { From 76c1c3ef2911ae5959ceb6eb71021cb3cfdadbda Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 18:44:28 +0100 Subject: [PATCH 0027/2811] Remove unused method --- .../Documentation/DocumentationSearchIndex.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php index b5b650c722f..b33845960a5 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php @@ -6,7 +6,6 @@ use Hyde\Pages\InMemoryPage; use Hyde\Pages\DocumentationPage; -use Hyde\Framework\Actions\StaticPageBuilder; use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; /** @@ -14,16 +13,6 @@ */ class DocumentationSearchIndex extends InMemoryPage { - /** - * Generate the search page and save it to disk. - * - * @return string The path to the generated file. - */ - public static function generate(): string - { - return StaticPageBuilder::handle(new static()); - } - /** * Create a new DocumentationSearchPage instance. */ From 44e97cd41508eccf6ce57142e2141fd14e0ee97b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 18:48:24 +0100 Subject: [PATCH 0028/2811] Merge in source directory prefix for search index identifier --- .../Features/Documentation/DocumentationSearchIndex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php index b33845960a5..f1dcaaa1acb 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php @@ -18,7 +18,7 @@ class DocumentationSearchIndex extends InMemoryPage */ public function __construct() { - parent::__construct('search.json', [ + parent::__construct(DocumentationPage::sourceDirectory().'/search.json', [ 'navigation' => ['hidden' => true], ]); } From 01cba90c8a9ac168e57f4f5001039bef0f3b9fd1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 19:46:01 +0100 Subject: [PATCH 0029/2811] Trim leading slashes from assembled paths --- .../Features/Documentation/DocumentationSearchIndex.php | 4 ++-- .../Features/Documentation/DocumentationSearchPage.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php index f1dcaaa1acb..4ad3e5deb30 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php @@ -18,7 +18,7 @@ class DocumentationSearchIndex extends InMemoryPage */ public function __construct() { - parent::__construct(DocumentationPage::sourceDirectory().'/search.json', [ + parent::__construct(ltrim(DocumentationPage::sourceDirectory().'/search.json', '/'), [ 'navigation' => ['hidden' => true], ]); } @@ -30,6 +30,6 @@ public function compile(): string public function getOutputPath(): string { - return DocumentationPage::outputDirectory().'/search.json'; + return ltrim(DocumentationPage::outputDirectory().'/search.json', '/'); } } diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index f58ff0b83ca..b582111b529 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -52,6 +52,6 @@ public static function enabled(): bool public static function routeKey(): string { - return parent::outputDirectory().'/search'; + return ltrim(parent::outputDirectory().'/search'); } } From 57bdecb2bc2c593c9cf5ed129953f559a3fe115d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 19:50:38 +0100 Subject: [PATCH 0030/2811] Inline added simplified experimental method --- .../framework/src/Console/Commands/BuildSearchCommand.php | 4 ++-- packages/framework/src/Foundation/HydeCoreExtension.php | 4 ++-- .../Actions/GeneratesDocumentationSearchIndex.php | 8 -------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSearchCommand.php b/packages/framework/src/Console/Commands/BuildSearchCommand.php index 563778da0b1..814f69ed751 100644 --- a/packages/framework/src/Console/Commands/BuildSearchCommand.php +++ b/packages/framework/src/Console/Commands/BuildSearchCommand.php @@ -7,8 +7,8 @@ use Hyde\Foundation\Facades\Pages; use Hyde\Framework\Actions\StaticPageBuilder; use LaravelZero\Framework\Commands\Command; -use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; use Hyde\Framework\Features\Documentation\DocumentationSearchPage; +use Hyde\Framework\Features\Documentation\DocumentationSearchIndex; /** * Run the build process for the documentation search index. @@ -23,7 +23,7 @@ class BuildSearchCommand extends Command public function handle(): int { - StaticPageBuilder::handle(Pages::get('search.json') ?? GeneratesDocumentationSearchIndex::makePage()); + StaticPageBuilder::handle(Pages::get('search.json') ?? DocumentationSearchIndex::make()); if (DocumentationSearchPage::enabled()) { StaticPageBuilder::handle(Pages::get('docs/search') ?? new DocumentationSearchPage()); diff --git a/packages/framework/src/Foundation/HydeCoreExtension.php b/packages/framework/src/Foundation/HydeCoreExtension.php index 50d5d40a0ed..5ecf1e90ef2 100644 --- a/packages/framework/src/Foundation/HydeCoreExtension.php +++ b/packages/framework/src/Foundation/HydeCoreExtension.php @@ -12,8 +12,8 @@ use Hyde\Foundation\Kernel\PageCollection; use Hyde\Foundation\Concerns\HydeExtension; use Hyde\Facades\Features; -use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; use Hyde\Framework\Features\Documentation\DocumentationSearchPage; +use Hyde\Framework\Features\Documentation\DocumentationSearchIndex; use function array_filter; use function array_keys; @@ -35,7 +35,7 @@ public static function getPageClasses(): array public function discoverPages(PageCollection $collection): void { if (Features::hasDocumentationSearch()) { - $collection->addPage(GeneratesDocumentationSearchIndex::makePage()); + $collection->addPage(DocumentationSearchIndex::make()); if (DocumentationSearchPage::enabled()) { $collection->addPage(new DocumentationSearchPage()); diff --git a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php index e76c20496dd..64bbb7d8e67 100644 --- a/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Actions/GeneratesDocumentationSearchIndex.php @@ -7,11 +7,9 @@ use Hyde\Hyde; use Hyde\Facades\Config; use Hyde\Facades\Filesystem; -use Hyde\Pages\InMemoryPage; use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Pages\DocumentationPage; use Illuminate\Support\Collection; -use Hyde\Framework\Features\Documentation\DocumentationSearchIndex; use function basename; use function in_array; @@ -52,12 +50,6 @@ public static function generate(): string return $service->index->toJson(); } - /** @experimental May be moved to a DocumentationSearch class */ - public static function makePage(): InMemoryPage - { - return DocumentationSearchIndex::make(); - } - protected function __construct() { $this->index = new Collection(); From cca3610b786864df861a769c744a4d8db9793fc1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 19:52:21 +0100 Subject: [PATCH 0031/2811] Change constructor style Just makes it visually consistent --- packages/framework/src/Console/Commands/BuildSearchCommand.php | 2 +- packages/framework/src/Foundation/HydeCoreExtension.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSearchCommand.php b/packages/framework/src/Console/Commands/BuildSearchCommand.php index 814f69ed751..d73a9112500 100644 --- a/packages/framework/src/Console/Commands/BuildSearchCommand.php +++ b/packages/framework/src/Console/Commands/BuildSearchCommand.php @@ -23,7 +23,7 @@ class BuildSearchCommand extends Command public function handle(): int { - StaticPageBuilder::handle(Pages::get('search.json') ?? DocumentationSearchIndex::make()); + StaticPageBuilder::handle(Pages::get('search.json') ?? new DocumentationSearchIndex()); if (DocumentationSearchPage::enabled()) { StaticPageBuilder::handle(Pages::get('docs/search') ?? new DocumentationSearchPage()); diff --git a/packages/framework/src/Foundation/HydeCoreExtension.php b/packages/framework/src/Foundation/HydeCoreExtension.php index 5ecf1e90ef2..38772c55871 100644 --- a/packages/framework/src/Foundation/HydeCoreExtension.php +++ b/packages/framework/src/Foundation/HydeCoreExtension.php @@ -35,7 +35,7 @@ public static function getPageClasses(): array public function discoverPages(PageCollection $collection): void { if (Features::hasDocumentationSearch()) { - $collection->addPage(DocumentationSearchIndex::make()); + $collection->addPage(new DocumentationSearchIndex()); if (DocumentationSearchPage::enabled()) { $collection->addPage(new DocumentationSearchPage()); From 37f7046251b8c0514b8d8ef821de4ef3d35bbac8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 14 Dec 2023 20:05:28 +0100 Subject: [PATCH 0032/2811] Refractor internal search page to extend in memory page I think this is more semantic --- .../Documentation/DocumentationSearchPage.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index b582111b529..0bf7f8ad8c6 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -5,10 +5,10 @@ namespace Hyde\Framework\Features\Documentation; use Hyde\Hyde; +use Hyde\Pages\InMemoryPage; use Hyde\Pages\DocumentationPage; use Hyde\Framework\Actions\StaticPageBuilder; use Hyde\Facades\Config; -use Illuminate\Support\Facades\View; /** * @internal This page is used to render the search page for the documentation. @@ -17,7 +17,7 @@ * If you want to override this page, you can create a page with the route key "docs/search", * then this class will not be applied. For example, `_pages/docs/search.blade.php`. */ -class DocumentationSearchPage extends DocumentationPage +class DocumentationSearchPage extends InMemoryPage { /** * Generate the search page and save it to disk. @@ -34,15 +34,10 @@ public static function generate(): string */ public function __construct() { - parent::__construct('search', [ + parent::__construct(ltrim(DocumentationPage::outputDirectory().'/search', '/'), [ 'title' => 'Search', 'navigation' => ['hidden' => true], - ]); - } - - public function compile(): string - { - return View::make('hyde::pages.documentation-search')->render(); + ], view: 'hyde::pages.documentation-search'); } public static function enabled(): bool @@ -52,6 +47,6 @@ public static function enabled(): bool public static function routeKey(): string { - return ltrim(parent::outputDirectory().'/search'); + return ltrim(DocumentationPage::outputDirectory().'/search'); } } From 34ba8552a08210b82e597ede3472a534c62f1aeb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 11:12:57 +0100 Subject: [PATCH 0033/2811] Update documentation article component to support existing variables Allows for them to be passed from a model class, for example. --- RELEASE_NOTES.md | 1 + .../views/components/docs/documentation-article.blade.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index afe7ac9692f..d1ba26e97a6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -14,6 +14,7 @@ This serves two purposes: ### Changed - Changed how the documentation search is generated, to be an InMemoryPage instead of a post-build task. +- Updated the documentation article component to support existing $document instance. ### Deprecated - \Hyde\Framework\Actions\PostBuildTasks\GenerateSearch diff --git a/packages/framework/resources/views/components/docs/documentation-article.blade.php b/packages/framework/resources/views/components/docs/documentation-article.blade.php index 1bacc9e5c42..4565069d6a0 100644 --- a/packages/framework/resources/views/components/docs/documentation-article.blade.php +++ b/packages/framework/resources/views/components/docs/documentation-article.blade.php @@ -1,5 +1,5 @@ @php - $document = \Hyde\Framework\Features\Documentation\SemanticDocumentationArticle::make($page); + $document ??= \Hyde\Framework\Features\Documentation\SemanticDocumentationArticle::make($page); @endphp
Date: Fri, 15 Dec 2023 11:13:37 +0100 Subject: [PATCH 0034/2811] Update search page to mock document See https://github.com/hydephp/develop/commit/37f7046251b8c0514b8d8ef821de4ef3d35bbac8#commitcomment-135026537 --- .../Features/Documentation/DocumentationSearchPage.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index 0bf7f8ad8c6..af1c39b5892 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -37,6 +37,7 @@ public function __construct() parent::__construct(ltrim(DocumentationPage::outputDirectory().'/search', '/'), [ 'title' => 'Search', 'navigation' => ['hidden' => true], + 'document' => $this->makeDocument(), ], view: 'hyde::pages.documentation-search'); } @@ -49,4 +50,10 @@ public static function routeKey(): string { return ltrim(DocumentationPage::outputDirectory().'/search'); } + + /** @experimental Fixes type issue {@see https://github.com/hydephp/develop/commit/37f7046251b8c0514b8d8ef821de4ef3d35bbac8#commitcomment-135026537} */ + protected function makeDocument(): SemanticDocumentationArticle + { + return SemanticDocumentationArticle::make(new DocumentationPage()); + } } From b6eca700b4bb96037e55f7fe12071306fad2e074 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 11:36:00 +0100 Subject: [PATCH 0035/2811] Fix added search index page should include docs prefix These in-memory page identifiers should include the route key prefix they would get if they were documentation pages --- packages/framework/src/Console/Commands/BuildSearchCommand.php | 2 +- .../framework/tests/Feature/Commands/BuildSearchCommandTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSearchCommand.php b/packages/framework/src/Console/Commands/BuildSearchCommand.php index d73a9112500..4388c64cb68 100644 --- a/packages/framework/src/Console/Commands/BuildSearchCommand.php +++ b/packages/framework/src/Console/Commands/BuildSearchCommand.php @@ -23,7 +23,7 @@ class BuildSearchCommand extends Command public function handle(): int { - StaticPageBuilder::handle(Pages::get('search.json') ?? new DocumentationSearchIndex()); + StaticPageBuilder::handle(Pages::get('docs/search.json') ?? new DocumentationSearchIndex()); if (DocumentationSearchPage::enabled()) { StaticPageBuilder::handle(Pages::get('docs/search') ?? new DocumentationSearchPage()); diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index 454b63196d3..9dcdc335552 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -107,7 +107,7 @@ public function test_search_files_can_be_generated_for_custom_site_and_nested_do public function test_command_uses_search_pages_from_kernel_when_present() { - Hyde::pages()->addPage(tap(new InMemoryPage('search.json'), function (InMemoryPage $page): void { + Hyde::pages()->addPage(tap(new InMemoryPage('docs/search.json'), function (InMemoryPage $page): void { $page->macro('compile', fn () => '{"foo":"bar"}'); $page->macro('getOutputPath', fn () => 'docs/search.json'); })); From 6c932a1bf49cce15e0214a063532c85ca50d7306 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 11:38:23 +0100 Subject: [PATCH 0036/2811] Deprecate internal logic to be removed within refactor --- .../Framework/Features/Documentation/DocumentationSearchPage.php | 1 + packages/realtime-compiler/src/Routing/PageRouter.php | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index af1c39b5892..06530bb84a9 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -46,6 +46,7 @@ public static function enabled(): bool return Config::getBool('docs.create_search_page', true) && ! Hyde::routes()->has(self::routeKey()); } + /** @deprecated Can be removed by https://github.com/hydephp/develop/pull/1498 */ public static function routeKey(): string { return ltrim(DocumentationPage::outputDirectory().'/search'); diff --git a/packages/realtime-compiler/src/Routing/PageRouter.php b/packages/realtime-compiler/src/Routing/PageRouter.php index 1e41b531bd4..3d29cc7d18c 100644 --- a/packages/realtime-compiler/src/Routing/PageRouter.php +++ b/packages/realtime-compiler/src/Routing/PageRouter.php @@ -90,6 +90,7 @@ public static function handle(Request $request): Response protected function getPageFromRoute(): HydePage { + /** @deprecated Can be removed by https://github.com/hydephp/develop/pull/1498 */ if (unslash($this->request->path) === DocumentationSearchPage::routeKey() && DocumentationSearchPage::enabled()) { // Since this page is not present within the search index (as it's normally generated by a build task) // we instantiate and return it here. From 4556eed47894c9d5e5bd85aa85559445b9300cec Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 12:56:30 +0100 Subject: [PATCH 0037/2811] Fix wrong method used to emulate route key --- .../Features/Documentation/DocumentationSearchIndex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php index 4ad3e5deb30..2cb5aab6298 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchIndex.php @@ -18,7 +18,7 @@ class DocumentationSearchIndex extends InMemoryPage */ public function __construct() { - parent::__construct(ltrim(DocumentationPage::sourceDirectory().'/search.json', '/'), [ + parent::__construct(ltrim(DocumentationPage::outputDirectory().'/search.json', '/'), [ 'navigation' => ['hidden' => true], ]); } From 790689e0bfa3960e0585319801c299c6f2fa4bf0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 12:57:57 +0100 Subject: [PATCH 0038/2811] Create DocumentationSearchIndexTest.php --- .../Feature/DocumentationSearchIndexTest.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/framework/tests/Feature/DocumentationSearchIndexTest.php diff --git a/packages/framework/tests/Feature/DocumentationSearchIndexTest.php b/packages/framework/tests/Feature/DocumentationSearchIndexTest.php new file mode 100644 index 00000000000..58de0d066dd --- /dev/null +++ b/packages/framework/tests/Feature/DocumentationSearchIndexTest.php @@ -0,0 +1,36 @@ +assertInstanceOf(DocumentationSearchIndex::class, new DocumentationSearchIndex()); + } + + public function testRouteKeyIsSetToDocumentationOutputDirectory() + { + $page = new DocumentationSearchIndex(); + $this->assertSame('docs/search.json', $page->routeKey); + } + + public function testRouteKeyIsSetToConfiguredDocumentationOutputDirectory() + { + DocumentationPage::setOutputDirectory('foo'); + + $page = new DocumentationSearchIndex(); + $this->assertSame('foo/search.json', $page->routeKey); + } +} From 37c2dde6b063579dbdb3ad4444c9ae27b3ef27bc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 12:58:05 +0100 Subject: [PATCH 0039/2811] Add coverage annotation --- .../framework/tests/Feature/Commands/BuildSearchCommandTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index 9dcdc335552..faa5f89b75a 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -14,6 +14,7 @@ * @covers \Hyde\Console\Commands\BuildSearchCommand * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateSearch * @covers \Hyde\Framework\Features\Documentation\DocumentationSearchPage + * @covers \Hyde\Framework\Features\Documentation\DocumentationSearchIndex */ class BuildSearchCommandTest extends TestCase { From 38608b81dde77497e6a1283f0f3b9e81432ed039 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 13:32:59 +0100 Subject: [PATCH 0040/2811] Remove hacky route injection in favour of new search page implementation Targets the realtime compiler v4 as it's a breaking change that requires Hyde v2. See https://github.com/hydephp/develop/pull/1498 --- packages/realtime-compiler/src/Routing/PageRouter.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/realtime-compiler/src/Routing/PageRouter.php b/packages/realtime-compiler/src/Routing/PageRouter.php index 3d29cc7d18c..a3a3876203a 100644 --- a/packages/realtime-compiler/src/Routing/PageRouter.php +++ b/packages/realtime-compiler/src/Routing/PageRouter.php @@ -8,7 +8,6 @@ use Hyde\Pages\Concerns\BaseMarkdownPage; use Hyde\Framework\Actions\StaticPageBuilder; use Hyde\RealtimeCompiler\Http\LiveEditController; -use Hyde\Framework\Features\Documentation\DocumentationSearchPage; use Hyde\Pages\Concerns\HydePage; use Hyde\RealtimeCompiler\Concerns\InteractsWithLaravel; use Hyde\RealtimeCompiler\Concerns\SendsErrorResponses; @@ -90,13 +89,6 @@ public static function handle(Request $request): Response protected function getPageFromRoute(): HydePage { - /** @deprecated Can be removed by https://github.com/hydephp/develop/pull/1498 */ - if (unslash($this->request->path) === DocumentationSearchPage::routeKey() && DocumentationSearchPage::enabled()) { - // Since this page is not present within the search index (as it's normally generated by a build task) - // we instantiate and return it here. - return new DocumentationSearchPage(); - } - return Routes::getOrFail($this->normalizePath($this->request->path))->getPage(); } } From 9c100594e1292ebee8ab2c2329199fc71398fad3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 13:42:25 +0100 Subject: [PATCH 0041/2811] Update test to use new search page implementation --- packages/realtime-compiler/tests/RealtimeCompilerTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/realtime-compiler/tests/RealtimeCompilerTest.php b/packages/realtime-compiler/tests/RealtimeCompilerTest.php index 9f48e9467a9..5c2cec606c3 100644 --- a/packages/realtime-compiler/tests/RealtimeCompilerTest.php +++ b/packages/realtime-compiler/tests/RealtimeCompilerTest.php @@ -164,6 +164,8 @@ }); test('docs/search renders search page', function () { + Filesystem::put('_docs/index.md', '# Hello World!'); + mockRoute('docs/search'); $kernel = new HttpKernel(); @@ -175,6 +177,7 @@ expect($response->body)->toContain('Search the documentation site'); + Filesystem::unlink('_docs/index.md'); Filesystem::unlink('_site/docs/search.html'); }); From 0838ab4f25f75299f28495dcb9191e03a1ea0f3a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 15:10:29 +0100 Subject: [PATCH 0042/2811] Remove internal `DocumentationSearchPage::routeKey()` method This is now no longer needed thanks to https://github.com/hydephp/develop/pull/1498, but is kept as protected so the `enabled` method can use it --- .../Documentation/DocumentationSearchPage.php | 3 +-- .../tests/Feature/DocumentationSearchPageTest.php | 11 ----------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index 06530bb84a9..a27408c92fd 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -46,8 +46,7 @@ public static function enabled(): bool return Config::getBool('docs.create_search_page', true) && ! Hyde::routes()->has(self::routeKey()); } - /** @deprecated Can be removed by https://github.com/hydephp/develop/pull/1498 */ - public static function routeKey(): string + protected static function routeKey(): string { return ltrim(DocumentationPage::outputDirectory().'/search'); } diff --git a/packages/framework/tests/Feature/DocumentationSearchPageTest.php b/packages/framework/tests/Feature/DocumentationSearchPageTest.php index 22a9b53ed1c..ec91f318044 100644 --- a/packages/framework/tests/Feature/DocumentationSearchPageTest.php +++ b/packages/framework/tests/Feature/DocumentationSearchPageTest.php @@ -59,15 +59,4 @@ public function testEnabledIsFalseWhenDisabledAndRouteExists() Hyde::routes()->put('docs/search', new InMemoryPage('docs/search')); $this->assertFalse(DocumentationSearchPage::enabled()); } - - public function testStaticRouteKeyHelper() - { - $this->assertSame('docs/search', DocumentationSearchPage::routeKey()); - } - - public function testStaticRouteKeyHelperWithCustomOutputDirectory() - { - DocumentationPage::setOutputDirectory('foo'); - $this->assertSame('foo/search', DocumentationSearchPage::routeKey()); - } } From 82dc71f4a0e7b6be7a9f8d822fbebe39d2289ced Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 15:50:21 +0100 Subject: [PATCH 0043/2811] Add improved conditional to fix override priority As part of the v2 refactors, since routes aren't discovered yet, we need to check the pages directly. This also means that custom search pages are now not built by the build:search command. We could change it so that it is, but we don't know if the custom page is a custom search feature, or a page that documents a search feature. So we don't know if this is what the user would want/expect. Additionally, the kernel API changes to needing to put the overrides in the pages collection instead of the route collection. This is also a very very minor implementation change with minimal impact. --- .../Features/Documentation/DocumentationSearchPage.php | 9 ++++++++- .../tests/Feature/Commands/BuildSearchCommandTest.php | 6 +++--- .../tests/Feature/DocumentationSearchPageTest.php | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index a27408c92fd..a352a250358 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -7,6 +7,7 @@ use Hyde\Hyde; use Hyde\Pages\InMemoryPage; use Hyde\Pages\DocumentationPage; +use Hyde\Pages\Concerns\HydePage; use Hyde\Framework\Actions\StaticPageBuilder; use Hyde\Facades\Config; @@ -43,7 +44,13 @@ public function __construct() public static function enabled(): bool { - return Config::getBool('docs.create_search_page', true) && ! Hyde::routes()->has(self::routeKey()); + return Config::getBool('docs.create_search_page', true) && ! static::anotherSearchPageExists(); + } + + protected static function anotherSearchPageExists(): bool + { + // Since routes aren't discovered yet, we need to check the pages directly + return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null; } protected static function routeKey(): string diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index faa5f89b75a..dfcf392d5bf 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -120,12 +120,12 @@ public function test_command_uses_search_pages_from_kernel_when_present() $this->artisan('build:search')->assertExitCode(0); $this->assertFileExists(Hyde::path('_site/docs/search.json')); - $this->assertFileExists(Hyde::path('_site/docs/search.html')); +// $this->assertFileExists(Hyde::path('_site/docs/search.html')); $this->assertSame('{"foo":"bar"}', Filesystem::getContents('_site/docs/search.json')); - $this->assertSame('Foo', Filesystem::getContents('_site/docs/search.html')); +// $this->assertSame('Foo', Filesystem::getContents('_site/docs/search.html')); Filesystem::unlink('_site/docs/search.json'); - Filesystem::unlink('_site/docs/search.html'); +// Filesystem::unlink('_site/docs/search.html'); } } diff --git a/packages/framework/tests/Feature/DocumentationSearchPageTest.php b/packages/framework/tests/Feature/DocumentationSearchPageTest.php index ec91f318044..9f1d2546bec 100644 --- a/packages/framework/tests/Feature/DocumentationSearchPageTest.php +++ b/packages/framework/tests/Feature/DocumentationSearchPageTest.php @@ -49,14 +49,14 @@ public function testEnabledIsFalseWhenDisabled() public function testEnabledIsFalseWhenRouteExists() { - Hyde::routes()->put('docs/search', new InMemoryPage('docs/search')); + Hyde::pages()->put('docs/search', new InMemoryPage('docs/search')); $this->assertFalse(DocumentationSearchPage::enabled()); } public function testEnabledIsFalseWhenDisabledAndRouteExists() { config(['docs.create_search_page' => false]); - Hyde::routes()->put('docs/search', new InMemoryPage('docs/search')); + Hyde::pages()->put('docs/search', new InMemoryPage('docs/search')); $this->assertFalse(DocumentationSearchPage::enabled()); } } From 53d41b81c8e916f0fcc4246b2fa05f51b9079d59 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 16 Dec 2023 16:40:15 +0100 Subject: [PATCH 0044/2811] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d1ba26e97a6..31f6df9770b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -39,3 +39,16 @@ The documentation search page and search index have been changed to be generated In case you have customized the GenerateSearch post-build task, you will need to adapt your code to the new InMemoryPage, which is generated in the HydeCoreExtension class. For more information, see https://github.com/hydephp/develop/pull/1498. + +### Breaking changes + +#### Low impact +- The `GenerateSearch` post-build task has been removed. If you have previously extended or customized this class, + you will need to adapt your code, as the search index files are now handled implicitly during the standard build process, + as the search pages are now added to the kernel page and route collection. (https://github.com/hydephp/develop/pull/1498) +- If your site has a custom documentation search page, for example `_docs/search.md` or `_pages/docs/search.blade.php`, + that page will no longer be build when using the specific `build:search` command. It will, of course, + be built using the standard `build` command. https://github.com/hydephp/develop/commit/82dc71f4a0e7b6be7a9f8d822fbebe39d2289ced +- In the highly unlikely event your site customizes any of the search pages by replacing them in the kernel route collection, + you would now need to do that in the kernel page collection due to the search pages being generated earlier in the lifecycle. + https://github.com/hydephp/develop/commit/82dc71f4a0e7b6be7a9f8d822fbebe39d2289ced From 3bad9138c1e785f3b2a28c7c0530e1fc93bcc14f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 17 Dec 2023 19:59:55 +0100 Subject: [PATCH 0045/2811] Breaking: Remove the GenerateSearch build task --- .../Actions/PostBuildTasks/GenerateSearch.php | 34 ------------------- .../Commands/BuildSearchCommandTest.php | 1 - .../Feature/Services/BuildTaskServiceTest.php | 1 - .../tests/Unit/BuildTaskServiceUnitTest.php | 6 ---- 4 files changed, 42 deletions(-) delete mode 100644 packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSearch.php diff --git a/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSearch.php b/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSearch.php deleted file mode 100644 index a2d115a6e96..00000000000 --- a/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSearch.php +++ /dev/null @@ -1,34 +0,0 @@ -path = GeneratesDocumentationSearchIndex::handle(); - - if (DocumentationSearchPage::enabled()) { - $this->createdSiteFile(DocumentationSearchPage::generate()); - } - } - - public function printFinishMessage(): void - { - $this->createdSiteFile($this->path)->withExecutionTime(); - } -} diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index dfcf392d5bf..9562ae12512 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -12,7 +12,6 @@ /** * @covers \Hyde\Console\Commands\BuildSearchCommand - * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateSearch * @covers \Hyde\Framework\Features\Documentation\DocumentationSearchPage * @covers \Hyde\Framework\Features\Documentation\DocumentationSearchIndex */ diff --git a/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php b/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php index 0260d37a8f6..347f83530ca 100644 --- a/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php +++ b/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php @@ -19,7 +19,6 @@ * @covers \Hyde\Framework\Features\BuildTasks\PostBuildTask * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed - * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateSearch * * @see \Hyde\Framework\Testing\Unit\BuildTaskServiceUnitTest */ diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 1b08979d54f..bcf14ff42a2 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -8,7 +8,6 @@ use Hyde\Foundation\Kernel\Filesystem; use Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest; use Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed; -use Hyde\Framework\Actions\PostBuildTasks\GenerateSearch; use Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap as FrameworkGenerateSitemap; use Hyde\Framework\Features\BuildTasks\BuildTask; use Hyde\Framework\Features\BuildTasks\PostBuildTask; @@ -167,11 +166,6 @@ public function testGenerateRssFeedExtendsPostBuildTask() $this->assertInstanceOf(PostBuildTask::class, new GenerateRssFeed()); } - public function testGenerateSearchExtendsPostBuildTask() - { - $this->assertInstanceOf(PostBuildTask::class, new GenerateSearch()); - } - public function testGenerateSitemapExtendsPostBuildTask() { $this->assertInstanceOf(PostBuildTask::class, new FrameworkGenerateSitemap()); From aeeed9f4fab5edab6513ef1c5210e9a1a4e349e6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 17 Dec 2023 20:26:26 +0100 Subject: [PATCH 0046/2811] Cleanup and improve release notes --- RELEASE_NOTES.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 31f6df9770b..599dcd1e614 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -10,17 +10,17 @@ This serves two purposes: 2. At release time, you can move the Unreleased section changes into a new release version section. ### Added -- Add experimental InMemoryPage::getOutputPath overload support +- Add experimental `InMemoryPage::getOutputPath` overload support ### Changed -- Changed how the documentation search is generated, to be an InMemoryPage instead of a post-build task. -- Updated the documentation article component to support existing $document instance. +- Changed how the documentation search is generated, to be an `InMemoryPage` instead of a post-build task. +- Updated the documentation article component to support existing `$document` instance. ### Deprecated -- \Hyde\Framework\Actions\PostBuildTasks\GenerateSearch +- for soon-to-be removed features. ### Removed -- for now removed features. +- Breaking: Removed the build task `\Hyde\Framework\Actions\PostBuildTasks\GenerateSearch` (see upgrade guide below) ### Fixed - for any bug fixes. @@ -32,23 +32,29 @@ This serves two purposes: If there are any breaking changes, include an upgrade guide here. -#### Documentation search changes +#### Documentation search page changes -The documentation search page and search index have been changed to be generated as InMemoryPages instead of a post-build task. +The documentation search page and search index have been changed to be generated as `InMemoryPages` instead of a post-build task. -In case you have customized the GenerateSearch post-build task, you will need to adapt your code to the new InMemoryPage, which is generated in the HydeCoreExtension class. +The main impact noticeable to most users by this is the implicit changes, like the pages showing up in the dashboard and route list command. + +In case you have customized the `GenerateSearch` post-build task you may, depending on what you were trying to do, +want to adapt your code to interact with the new `InMemoryPage`, which is generated in the `HydeCoreExtension` class. For more information, see https://github.com/hydephp/develop/pull/1498. ### Breaking changes #### Low impact + - The `GenerateSearch` post-build task has been removed. If you have previously extended or customized this class, you will need to adapt your code, as the search index files are now handled implicitly during the standard build process, as the search pages are now added to the kernel page and route collection. (https://github.com/hydephp/develop/pull/1498) + - If your site has a custom documentation search page, for example `_docs/search.md` or `_pages/docs/search.blade.php`, - that page will no longer be build when using the specific `build:search` command. It will, of course, + that page will no longer be built when using the specific `build:search` command. It will, of course, be built using the standard `build` command. https://github.com/hydephp/develop/commit/82dc71f4a0e7b6be7a9f8d822fbebe39d2289ced +- - In the highly unlikely event your site customizes any of the search pages by replacing them in the kernel route collection, you would now need to do that in the kernel page collection due to the search pages being generated earlier in the lifecycle. https://github.com/hydephp/develop/commit/82dc71f4a0e7b6be7a9f8d822fbebe39d2289ced From e43d6e829ce914422cf927c21bbc0575b105b145 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 18 Dec 2023 10:47:03 +0100 Subject: [PATCH 0047/2811] Improve code comment --- .../Features/Documentation/DocumentationSearchPage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index a352a250358..27150145f3d 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -49,7 +49,8 @@ public static function enabled(): bool protected static function anotherSearchPageExists(): bool { - // Since routes aren't discovered yet, we need to check the pages directly + // Since routes aren't discovered yet due to this page being added in the core extension, + // we need to check the page collection directly, instead of the route collection. return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null; } From 32a1ee5e085bf367d96a6546acfa2d05672c26f3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 18 Dec 2023 10:46:00 +0100 Subject: [PATCH 0048/2811] Use helper method with same code --- .../Features/Documentation/DocumentationSearchPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index 27150145f3d..e3070f59897 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -35,7 +35,7 @@ public static function generate(): string */ public function __construct() { - parent::__construct(ltrim(DocumentationPage::outputDirectory().'/search', '/'), [ + parent::__construct(static::routeKey(), [ 'title' => 'Search', 'navigation' => ['hidden' => true], 'document' => $this->makeDocument(), From eb07152ae1cdece442145fd5f44808d74234e912 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 18 Dec 2023 11:12:23 +0100 Subject: [PATCH 0049/2811] Revert "Remove internal `DocumentationSearchPage::routeKey()` method" This reverts commit 0838ab4f25f75299f28495dcb9191e03a1ea0f3a as the class is internal it doesn't bog up the public API, but we can still use it to reduce overlapping logic in our codebase. --- .../Documentation/DocumentationSearchPage.php | 3 ++- .../tests/Feature/DocumentationSearchPageTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index e3070f59897..d5d90690c25 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -54,7 +54,8 @@ protected static function anotherSearchPageExists(): bool return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null; } - protected static function routeKey(): string + /** @deprecated Can be removed by https://github.com/hydephp/develop/pull/1498 */ + public static function routeKey(): string { return ltrim(DocumentationPage::outputDirectory().'/search'); } diff --git a/packages/framework/tests/Feature/DocumentationSearchPageTest.php b/packages/framework/tests/Feature/DocumentationSearchPageTest.php index 9f1d2546bec..cfb45b76a0c 100644 --- a/packages/framework/tests/Feature/DocumentationSearchPageTest.php +++ b/packages/framework/tests/Feature/DocumentationSearchPageTest.php @@ -59,4 +59,15 @@ public function testEnabledIsFalseWhenDisabledAndRouteExists() Hyde::pages()->put('docs/search', new InMemoryPage('docs/search')); $this->assertFalse(DocumentationSearchPage::enabled()); } + + public function testStaticRouteKeyHelper() + { + $this->assertSame('docs/search', DocumentationSearchPage::routeKey()); + } + + public function testStaticRouteKeyHelperWithCustomOutputDirectory() + { + DocumentationPage::setOutputDirectory('foo'); + $this->assertSame('foo/search', DocumentationSearchPage::routeKey()); + } } From ef0fa703c47ec82f9218bb8eab1b325efefc6deb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 18 Dec 2023 11:13:49 +0100 Subject: [PATCH 0050/2811] Revert internal deprecation This partially reverts commit 6c932a1bf49cce15e0214a063532c85ca50d7306. --- .../Framework/Features/Documentation/DocumentationSearchPage.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index d5d90690c25..d61a24b8105 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -54,7 +54,6 @@ protected static function anotherSearchPageExists(): bool return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null; } - /** @deprecated Can be removed by https://github.com/hydephp/develop/pull/1498 */ public static function routeKey(): string { return ltrim(DocumentationPage::outputDirectory().'/search'); From 883c09d9474ac9d003fede67f9f21e6ad2131186 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 18 Dec 2023 11:21:48 +0100 Subject: [PATCH 0051/2811] Move up public method --- .../Features/Documentation/DocumentationSearchPage.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index d61a24b8105..f9d92c1556e 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -47,6 +47,11 @@ public static function enabled(): bool return Config::getBool('docs.create_search_page', true) && ! static::anotherSearchPageExists(); } + public static function routeKey(): string + { + return ltrim(DocumentationPage::outputDirectory().'/search'); + } + protected static function anotherSearchPageExists(): bool { // Since routes aren't discovered yet due to this page being added in the core extension, @@ -54,11 +59,6 @@ protected static function anotherSearchPageExists(): bool return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null; } - public static function routeKey(): string - { - return ltrim(DocumentationPage::outputDirectory().'/search'); - } - /** @experimental Fixes type issue {@see https://github.com/hydephp/develop/commit/37f7046251b8c0514b8d8ef821de4ef3d35bbac8#commitcomment-135026537} */ protected function makeDocument(): SemanticDocumentationArticle { From 89c63523196e5816938b3a9eecb957041faffaad Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 18 Dec 2023 11:21:59 +0100 Subject: [PATCH 0052/2811] Import used function --- .../Features/Documentation/DocumentationSearchPage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index f9d92c1556e..4e6c1778678 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -11,6 +11,8 @@ use Hyde\Framework\Actions\StaticPageBuilder; use Hyde\Facades\Config; +use function ltrim; + /** * @internal This page is used to render the search page for the documentation. * From 0f8fe02c68cace2d5ab9567195d8f6d7e6ce243c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 18 Dec 2023 11:35:38 +0100 Subject: [PATCH 0053/2811] Fix missing trim argument Required in case of root outputs so that the route key is relative --- .../Features/Documentation/DocumentationSearchPage.php | 2 +- .../framework/tests/Feature/DocumentationSearchPageTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index 4e6c1778678..e16fe950279 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -51,7 +51,7 @@ public static function enabled(): bool public static function routeKey(): string { - return ltrim(DocumentationPage::outputDirectory().'/search'); + return ltrim(DocumentationPage::outputDirectory().'/search', '/'); } protected static function anotherSearchPageExists(): bool diff --git a/packages/framework/tests/Feature/DocumentationSearchPageTest.php b/packages/framework/tests/Feature/DocumentationSearchPageTest.php index cfb45b76a0c..e7a2adc4dc3 100644 --- a/packages/framework/tests/Feature/DocumentationSearchPageTest.php +++ b/packages/framework/tests/Feature/DocumentationSearchPageTest.php @@ -70,4 +70,10 @@ public function testStaticRouteKeyHelperWithCustomOutputDirectory() DocumentationPage::setOutputDirectory('foo'); $this->assertSame('foo/search', DocumentationSearchPage::routeKey()); } + + public function testStaticRouteKeyHelperWithRootOutputDirectory() + { + DocumentationPage::setOutputDirectory(''); + $this->assertSame('search', DocumentationSearchPage::routeKey()); + } } From b7a253777b8c0caca3d697f679fba3bb30450810 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 18 Dec 2023 11:43:30 +0100 Subject: [PATCH 0054/2811] Extract internal route key helper Reduces the amount of times and places we call the exact same logic --- .../components/docs/search-scripts.blade.php | 2 +- .../GeneratesDocumentationSearchIndex.php | 3 ++- .../Documentation/DocumentationSearchIndex.php | 9 ++++++++- .../Feature/DocumentationSearchIndexTest.php | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/framework/resources/views/components/docs/search-scripts.blade.php b/packages/framework/resources/views/components/docs/search-scripts.blade.php index 0d381221c29..f2561c84b61 100644 --- a/packages/framework/resources/views/components/docs/search-scripts.blade.php +++ b/packages/framework/resources/views/components/docs/search-scripts.blade.php @@ -1,7 +1,7 @@