Skip to content

Commit

Permalink
feat: fixing sitemap (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Feb 20, 2024
1 parent 08550b7 commit fe2c0e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 78 deletions.
20 changes: 0 additions & 20 deletions app/Console/Commands/CustomCrawlProfile.php

This file was deleted.

22 changes: 21 additions & 1 deletion app/Console/Commands/GenerateSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Psr\Http\Message\UriInterface;
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Sitemap\SitemapIndex;
use Spatie\Sitemap\Tags\Sitemap as SitemapTag;
use Spatie\Sitemap\Tags\Url;

class GenerateSitemap extends Command
{
Expand Down Expand Up @@ -55,9 +58,26 @@ public function handle(): void
*/
private function sitemap_root(SitemapIndex $sitemapIndex): void
{
$file = $this->file('sitemap_00.xml');
$file = $this->file('sitemap_root.xml');

SitemapGenerator::create(config('app.url'))
->configureCrawler(function (Crawler $crawler) {
$crawler->ignoreRobots();
})
->shouldCrawl(function (UriInterface $url): bool {
return $url->getQuery() === ''
&& ! Str::isMatch('/\/prenoms\/\d+\/\w+/', $url->getPath());
})
->hasCrawled(function (Url $url) {
$frequency = Str::isMatch('/\/public\/\w+/', $url->url)
|| Str::isMatch('/\/prenoms\/\d+\/\w+/', $url->url)
|| Str::finish($url->url, '/') === Str::finish(config('app.url'), '/')
? Url::CHANGE_FREQUENCY_WEEKLY
: Url::CHANGE_FREQUENCY_MONTHLY;
$url->setChangeFrequency($frequency);

return $url;
})
->writeToFile($file['file']);

$sitemapIndex->add(SitemapTag::create($file['url']));
Expand Down
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
$schedule->command('cloudflare:reload')->daily();
$schedule->command('sitemap:generate')->daily();
}

/**
Expand Down
57 changes: 0 additions & 57 deletions config/sitemap.php

This file was deleted.

0 comments on commit fe2c0e2

Please sign in to comment.