Add (custom crawl profile)

This commit is contained in:
2023-11-29 23:02:23 +08:00
parent ff7ff9309d
commit 5904418e8d
2 changed files with 30 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Helpers\FirstParty\SitemapCrawler;
use Spatie\Crawler\CrawlProfiles\CrawlProfile;
use Psr\Http\Message\UriInterface;
class CustomCrawlProfile extends CrawlProfile
{
/** @var callable */
protected $callback;
public function shouldCrawlCallback(callable $callback): void
{
$this->callback = $callback;
}
public function shouldCrawl(UriInterface $url): bool
{
if ($url->getQuery() !== '') {
return false;
}
return ($this->callback)($url);
}
}

View File

@@ -1,5 +1,6 @@
<?php
use App\Helpers\FirstParty\SitemapCrawler\CustomCrawlProfile;
use GuzzleHttp\RequestOptions;
use Spatie\Sitemap\Crawler\Profile;
@@ -52,6 +53,6 @@
* The sitemap generator uses a CrawlProfile implementation to determine
* which urls should be crawled for the sitemap.
*/
'crawl_profile' => Profile::class,
'crawl_profile' => CustomCrawlProfile::class,
];