Skip to content

Commit bd1cd3c

Browse files
committed
Refactor SitemapController and SitemapServiceProvider to allow for a default sitemap file name and update the route to only accept requests for the specific sitemap.xml file.
1 parent aaa668c commit bd1cd3c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Http/Controllers/SitemapController.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ public function __construct(Sitemap $sitemap)
2727
/**
2828
* Retrieve the content of the specified sitemap file.
2929
*
30-
* @param string $filename The name of the sitemap file.
30+
* @param string|null $filename The name of the sitemap file.
3131
*
32+
* @return Response
3233
* @throws FileNotFoundException
3334
*/
34-
public function __invoke(string $filename): Response
35+
public function __invoke(string $filename = null): Response
3536
{
37+
$filename = 'sitemap.xml';
38+
3639
$contents = $this->sitemap->getSitemapContents($filename);
3740

3841
return response($contents, 200)

src/SitemapServiceProvider.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public function configurePackage(Package $package): void
3636
*/
3737
public function PackageRegistered(): void
3838
{
39-
Route::get('/{filename}', SitemapController::class)
40-
->where('filename', '.*\.xml$')->name('sitemap');
39+
Route::get('/sitemap.xml', SitemapController::class)
40+
->where('filename', '.*\.xml$')
41+
->name('sitemap');
4142
}
4243
}

0 commit comments

Comments
 (0)