rapidez / sitemap
Rapidez sitemap index through Eventy filters
Requires
- php: ^8.1|^8.2
- ext-simplexml: *
- rapidez/core: ^2.0
Requires (Dev)
- larastan/larastan: ^2.5
- laravel/pint: ^1.7
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.0
- phpstan/phpstan-mockery: ^1.1
- phpunit/phpunit: ^10.1
This package is auto-updated.
Last update: 2024-12-13 10:36:25 UTC
README
Rapidez sitemap index through Eventy filters
Installation
composer require rapidez/sitemap
Configuration
You can publish the configuration file with:
php artisan vendor:publish --tag=config --provider="Rapidez\Sitemap\SitemapServiceProvider"
This will create a config/rapidez-sitemap.php
file where you can configure:
disk
: The Laravel filesystem disk to use (defaults to 'public')path
: The path within the disk where sitemaps will be stored (defaults to root)
Make sure the specified disk is properly configured in your application's config/filesystems.php
.
Views
You can publish the views with:
php artisan vendor:publish --tag=rapidez-sitemap-views
Sitemap Generation
To generate the sitemap manually, use:
php artisan rapidez:sitemap:generate
This command will generate sitemap.xml
for the default store and sitemap_{store_id}.xml
for additional stores in your configured storage location.
If you'd like to schedule the sitemap generation you can add the rapidez:sitemap:generate
command in routes/console.php
, for more information see Task Scheduling
Schedule::command('rapidez:sitemap:generate')->twiceDaily(0, 12);
Hooking into the Generation Action
When the rapidez:sitemap:generate
command runs, an Eventy action rapidez.sitemap.generate
is triggered.
You can hook into this generation process by adding an action in the boot
method of your service provider:
Eventy::addAction('rapidez.sitemap.generate', fn() => DoMagicHere(), 20, 1);
Adding Additional Sitemap Indexes with Eventy
If you have additional indexes, such as CMS pages or other custom routes, you can dynamically add them to your sitemap index based on the Store ID using the rapidez.site.{storeId}
filter provided by Eventy.
To do this, simply add the following code to the appropriate place in your application (e.g., in a service provider or a dedicated sitemap configuration file):
use TorMorten\Eventy\Facades\Eventy; Eventy::addFilter('rapidez.sitemap.{storeId}', function ($sitemaps) { // Add your custom sitemap URL here $sitemaps[] = [ 'url' => 'your-custom-sitemap.xml', 'lastmod' => now()->toDateString(), ]; return $sitemaps; }, 20, 1);
License
GNU General Public License v3. Please see License File for more information.