-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGenerateSitemap.php
40 lines (28 loc) · 1009 Bytes
/
GenerateSitemap.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
<?php
declare(strict_types=1);
namespace Hyde\Framework\Actions\PostBuildTasks;
use Hyde\Hyde;
use Hyde\Framework\Features\BuildTasks\PostBuildTask;
use Hyde\Framework\Concerns\InteractsWithDirectories;
use Hyde\Framework\Features\XmlGenerators\SitemapGenerator;
use function blank;
use function file_put_contents;
class GenerateSitemap extends PostBuildTask
{
use InteractsWithDirectories;
public static string $message = 'Generating sitemap';
protected string $path;
public function handle(): void
{
if (blank(Hyde::url()) || str_starts_with(Hyde::url(), 'http://localhost')) {
$this->skip('Cannot generate sitemap without a valid base URL');
}
$this->path = Hyde::sitePath('sitemap.xml');
$this->needsParentDirectory($this->path);
file_put_contents($this->path, SitemapGenerator::make());
}
public function printFinishMessage(): void
{
$this->createdSiteFile($this->path)->withExecutionTime();
}
}