1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Commands; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Concerns\ActionCommand; |
6
|
|
|
use Hyde\Framework\Helpers\Features; |
7
|
|
|
use Hyde\Framework\Hyde; |
8
|
|
|
use Hyde\Framework\Services\SitemapService; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Hyde Command to run the Build Process for the Sitemap. |
12
|
|
|
* |
13
|
|
|
* @see \Hyde\Framework\Testing\Feature\Commands\HydeBuildSitemapCommandTest |
14
|
|
|
*/ |
15
|
|
|
class HydeBuildSitemapCommand extends ActionCommand |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* The signature of the command. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $signature = 'build:sitemap'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The description of the command. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Generate the sitemap.xml'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Execute the console command. |
33
|
|
|
* |
34
|
|
|
* @return int |
35
|
|
|
*/ |
36
|
|
|
public function handle(): int |
37
|
|
|
{ |
38
|
|
|
if (! $this->runPreflightCheck()) { |
39
|
|
|
return 1; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$this->action('Generating sitemap', function () { |
43
|
|
|
file_put_contents( |
44
|
|
|
Hyde::getSiteOutputPath('sitemap.xml'), |
45
|
|
|
SitemapService::generateSitemap() |
46
|
|
|
); |
47
|
|
|
}, 'Created <info>sitemap.xml</info>'); |
48
|
|
|
|
49
|
|
|
return 0; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function runPreflightCheck(): bool |
53
|
|
|
{ |
54
|
|
|
if (! Features::sitemap()) { |
55
|
|
|
$this->error('Cannot generate sitemap.xml, please check your configuration.'); |
56
|
|
|
|
57
|
|
|
if (! Hyde::hasSiteUrl()) { |
58
|
|
|
$this->warn('Hint: You don\'t have a site URL configured. Check config/hyde.php'); |
59
|
|
|
} |
60
|
|
|
if (config('site.generate_sitemap', true) !== true) { |
61
|
|
|
$this->warn('Hint: You have disabled sitemap generation in config/hyde.php'); |
62
|
|
|
$this->line(' > You can enable sitemap generation by setting <info>`site.generate_sitemap`</> to <info>`true`</>'); |
63
|
|
|
} |
64
|
|
|
if (! extension_loaded('simplexml') || config('testing.mock_disabled_extensions', false) === true) { |
65
|
|
|
$this->warn('Hint: You don\'t have the <info>`simplexml`</> extension installed. Check your PHP installation.'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return true; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|