-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHydeBuildSearchCommand.php
86 lines (70 loc) · 2.48 KB
/
HydeBuildSearchCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Hyde\Framework\Commands;
use Hyde\Framework\Actions\GeneratesDocumentationSearchIndexFile;
use Hyde\Framework\Hyde;
use Hyde\Framework\Services\CollectionService;
use LaravelZero\Framework\Commands\Command;
/**
* Hyde Command to run the Build Process for the DocumentationSearchIndex.
*
* @todo Add configuration option to enable/disable this feature.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydeBuildSearchCommandTest
*/
class HydeBuildSearchCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'build:search';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Generate the docs/search.json';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$actionTime = microtime(true);
$this->comment('Generating documentation site search index...');
$expected = $this->guesstimateGenerationTime();
if ($expected > 0) {
$this->line("<fg=gray> > This will take an estimated $expected seconds. Terminal may seem non-responsive.</>");
}
GeneratesDocumentationSearchIndexFile::run();
$this->line(' > Created <info>'.GeneratesDocumentationSearchIndexFile::$filePath.'</> in '.
$this->getExecutionTimeInMs($actionTime)."ms\n");
if (config('docs.create_search_page', true)) {
$this->createSearchPage();
}
return 0;
}
protected function createSearchPage(): void
{
$actionTime = microtime(true);
$this->comment('Generating search page...');
file_put_contents(
Hyde::path('_site/'.config('docs.output_directory', 'docs').'/search.html'),
view('hyde::pages.documentation-search')->render()
);
$this->line(' > Created <info>_site/'.config('docs.output_directory', 'docs').'/search.html</> in '.
$this->getExecutionTimeInMs($actionTime)."ms\n");
}
/** @internal Estimated processing time per file in ms */
public static float $guesstimationFactor = 52.5;
protected function guesstimateGenerationTime(): int
{
return round(count(CollectionService::getDocumentationPageFiles()) * static::$guesstimationFactor) / 1000;
}
protected function getExecutionTimeInMs(float $timeStart): string
{
return number_format(((microtime(true) - $timeStart) * 1000), 2);
}
}