Skip to content

Commit c1d587a

Browse files
committed
Refactor sitemap generation and routing logic. Simplify the route for the sitemap and remove the need for a filename parameter in the SitemapController.
1 parent b27782f commit c1d587a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ php artisan sitemap:generate
116116
You can link to the sitemap with:
117117

118118
```blade
119-
route('sitemap', ['filename' => 'sitemap.xml'])
119+
route('sitemap')
120120
```
121121

122122

src/Http/Controllers/SitemapController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class SitemapController extends BaseController
1616
{
1717
protected Sitemap $sitemap;
18+
protected $defaultFilename = 'sitemap.xml';
1819

1920
/**
2021
* SitemapController constructor.
@@ -31,9 +32,9 @@ public function __construct(Sitemap $sitemap)
3132
*
3233
* @throws FileNotFoundException
3334
*/
34-
public function __invoke(?string $filename): Response
35+
public function __invoke(): Response
3536
{
36-
$contents = $this->sitemap->getSitemapContents($filename);
37+
$contents = $this->sitemap->getSitemapContents($this->defaultFilename);
3738

3839
return response($contents, 200)
3940
->header('Content-Type', 'application/xml');

src/SitemapServiceProvider.php

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

0 commit comments

Comments
 (0)