Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fixing sitemap #58

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading