mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 02:04:03 +00:00
3.x redesign
This commit is contained in:
parent
857122540f
commit
f8f354c323
229 changed files with 201175 additions and 22440 deletions
47
listeners/GenerateSitemap.php
Normal file
47
listeners/GenerateSitemap.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use samdark\sitemap\Sitemap;
|
||||
use TightenCo\Jigsaw\Jigsaw;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class GenerateSitemap
|
||||
{
|
||||
protected $exclude = [
|
||||
'/assets/*',
|
||||
'*/favicon.ico',
|
||||
'*/404',
|
||||
];
|
||||
|
||||
public function handle(Jigsaw $jigsaw)
|
||||
{
|
||||
$baseUrl = $jigsaw->getConfig('baseUrl');
|
||||
|
||||
if (!$baseUrl) {
|
||||
echo "\nTo generate a sitemap.xml file, please specify a 'baseUrl' in config.php.\n\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$sitemap = new Sitemap($jigsaw->getDestinationPath().'/sitemap.xml');
|
||||
|
||||
collect($jigsaw->getOutputPaths())
|
||||
->reject(function ($path) {
|
||||
return $this->isExcluded($path);
|
||||
})->each(function ($path) use ($baseUrl, $sitemap) {
|
||||
if (! Str::startsWith($path, '/')) {
|
||||
$path = '/' . $path; // Fix bug with `docs/v1` being present in getOutputPaths()
|
||||
}
|
||||
|
||||
$sitemap->addItem(rtrim($baseUrl, '/').$path, time(), Sitemap::DAILY);
|
||||
});
|
||||
|
||||
$sitemap->write();
|
||||
}
|
||||
|
||||
public function isExcluded($path)
|
||||
{
|
||||
return Str::is($this->exclude, $path);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue