Skip to content

Commit 7bdb657

Browse files
committed
Refactor sitemap generation and linking functionality. The changes were made to improve the flexibility and reusability of the code, allowing for dynamic sitemap filenames and routes.
1 parent a1c9c89 commit 7bdb657

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ You can generate the sitemap with:
113113
php artisan sitemap:generate
114114
```
115115

116+
You can link to the sitemap with:
117+
118+
```blade
119+
route('sitemap', ['filename' => 'sitemap.xml'])
120+
```
121+
122+
116123
## Testing
117124

118125
```bash

src/Http/Controllers/SitemapController.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public function __construct(Sitemap $sitemap)
3131
*
3232
* @throws FileNotFoundException
3333
*/
34-
public function __invoke(?string $filename = null): Response
34+
public function __invoke(?string $filename): Response
3535
{
36-
$filename = 'sitemap.xml';
37-
3836
$contents = $this->sitemap->getSitemapContents($filename);
3937

4038
return response($contents, 200)

src/SitemapServiceProvider.php

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

0 commit comments

Comments
 (0)