1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Actions\PostBuildTasks; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Concerns\InteractsWithDirectories; |
6
|
|
|
use Hyde\Framework\Contracts\AbstractBuildTask; |
7
|
|
|
use Hyde\Framework\Services\DiscoveryService; |
8
|
|
|
use Hyde\Framework\Services\DocumentationSearchService; |
9
|
|
|
|
10
|
|
|
class GenerateSearch extends AbstractBuildTask |
11
|
|
|
{ |
12
|
|
|
use InteractsWithDirectories; |
13
|
|
|
|
14
|
|
|
public static string $description = 'Generating search index'; |
15
|
|
|
|
16
|
|
|
public function run(): void |
17
|
|
|
{ |
18
|
|
|
$expected = $this->guesstimateGenerationTime(); |
19
|
|
|
if ($expected >= 1) { |
20
|
|
|
$this->line("<fg=gray>This will take an estimated $expected seconds. Terminal may seem non-responsive.</>"); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
DocumentationSearchService::generate(); |
24
|
|
|
|
25
|
|
|
if (config('docs.create_search_page', true)) { |
26
|
|
|
$directory = DocumentationSearchService::generateSearchPage(); |
27
|
|
|
|
28
|
|
|
$this->createdSiteFile("$directory/search.html"); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function then(): void |
33
|
|
|
{ |
34
|
|
|
$this->writeln(sprintf("\n > Created <info>%s</info> in %s", |
35
|
|
|
$this->normalizePath(DocumentationSearchService::$filePath), |
36
|
|
|
$this->getExecutionTime() |
37
|
|
|
)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function normalizePath(string $path): string |
41
|
|
|
{ |
42
|
|
|
return str_replace('\\', '/', $path); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** @internal Estimated processing time per file in ms */ |
46
|
|
|
public static float $guesstimationFactor = 52.5; |
47
|
|
|
|
48
|
|
|
protected function guesstimateGenerationTime(): int|float |
49
|
|
|
{ |
50
|
|
|
return (int) round(count(DiscoveryService::getDocumentationPageFiles()) * static::$guesstimationFactor) / 1000; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|