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