Skip to content

Commit

Permalink
Refactor SitemapController and SitemapServiceProvider to allow for de…
Browse files Browse the repository at this point in the history
…fault sitemap file name and update the route to only accept requests for the specific sitemap.xml file. (#13)

* 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.

* Fix styling

* Bump laravel/pint from 1.16.0 to 1.16.1 (#12)

Bumps [laravel/pint](https://github.com/laravel/pint) from 1.16.0 to 1.16.1.
- [Release notes](https://github.com/laravel/pint/releases)
- [Changelog](https://github.com/laravel/pint/blob/main/CHANGELOG.md)
- [Commits](laravel/pint@v1.16.0...v1.16.1)

---
updated-dependencies:
- dependency-name: laravel/pint
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Joshua Mitchener <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: thejmitchener <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 7, 2024
1 parent aaa668c commit 0f14318
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/Http/Controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public function __construct(Sitemap $sitemap)
/**
* Retrieve the content of the specified sitemap file.
*
* @param string $filename The name of the sitemap file.
* @param string|null $filename The name of the sitemap file.
*
* @throws FileNotFoundException
*/
public function __invoke(string $filename): Response
public function __invoke(?string $filename = null): Response
{
$filename = 'sitemap.xml';

$contents = $this->sitemap->getSitemapContents($filename);

return response($contents, 200)
Expand Down
5 changes: 3 additions & 2 deletions src/SitemapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function configurePackage(Package $package): void
*/
public function PackageRegistered(): void
{
Route::get('/{filename}', SitemapController::class)
->where('filename', '.*\.xml$')->name('sitemap');
Route::get('/sitemap.xml', SitemapController::class)
->where('filename', '.*\.xml$')
->name('sitemap');
}
}

0 comments on commit 0f14318

Please sign in to comment.