1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Hyde\Framework\Features\Documentation; |
6
|
|
|
|
7
|
|
|
use Hyde\Hyde; |
8
|
|
|
use Hyde\Pages\InMemoryPage; |
9
|
|
|
use Hyde\Pages\DocumentationPage; |
10
|
|
|
use Hyde\Pages\Concerns\HydePage; |
11
|
|
|
use Hyde\Support\Models\RouteKey; |
12
|
|
|
use Hyde\Facades\Config; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @internal This page is used to render the search page for the documentation. |
16
|
|
|
* |
17
|
|
|
* It is not based on a source file, but is dynamically generated when the Search feature is enabled. |
18
|
|
|
* If you want to override this page, you can create a page with the route key "docs/search", |
19
|
|
|
* then this class will not be applied. For example, `_pages/docs/search.blade.php`. |
20
|
|
|
*/ |
21
|
|
|
class DocumentationSearchPage extends InMemoryPage |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Create a new DocumentationSearchPage instance. |
25
|
|
|
*/ |
26
|
|
|
public function __construct() |
27
|
|
|
{ |
28
|
|
|
parent::__construct(static::routeKey(), [ |
29
|
|
|
'title' => 'Search', |
30
|
|
|
'navigation' => ['hidden' => true], |
31
|
|
|
'article' => false, |
32
|
|
|
], view: 'hyde::pages.docs.search'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function enabled(): bool |
36
|
|
|
{ |
37
|
|
|
return Config::getBool('docs.create_search_page', true) && ! static::anotherSearchPageExists(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public static function routeKey(): string |
41
|
|
|
{ |
42
|
|
|
return RouteKey::fromPage(DocumentationPage::class, 'search')->get(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected static function anotherSearchPageExists(): bool |
46
|
|
|
{ |
47
|
|
|
// Since routes aren't discovered yet due to this page being added in the core extension, |
48
|
|
|
// we need to check the page collection directly, instead of the route collection. |
49
|
|
|
return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null; |
|
|
|
|
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|