daikazu/sitemap

This is my package sitemap

Fund package maintenance!
Daikazu

v1.0.0 2025-05-02 16:07 UTC

This package is auto-updated.

Last update: 2025-05-02 16:12:33 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel package for generating and managing XML sitemaps with caching and cooldown periods. This package provides an easy way to generate and maintain sitemaps for your Laravel applications while preventing excessive generation requests.

Features

  • Automatic sitemap generation with configurable cooldown periods
  • Caching of sitemap content for improved performance
  • Environment-aware generation (skips generation in local environment)
  • Force regeneration capability when needed
  • Built on top of the popular spatie/laravel-sitemap package
  • Automatic scheduling of sitemap generation

Installation

You can install the package via composer:

composer require daikazu/sitemap

You can publish the config file with:

php artisan vendor:publish --tag="sitemap-config"

This is the contents of the published config file:

return [
    // The cooldown period in hours between sitemap generations
    'cooldown_hours' => env('SITEMAP_COOLDOWN_HOURS', 24),

    // Schedule settings for automatic sitemap generation
    'schedule' => [
        // Enable or disable scheduled generation
        'enabled' => env('SITEMAP_SCHEDULE_ENABLED', true),

        // Time of day to run the daily generation (24-hour format)
        'daily_time' => env('SITEMAP_DAILY_TIME', '00:00'),

        // Interval in minutes to check for cooldown expiration
        'check_interval' => env('SITEMAP_CHECK_INTERVAL', 1),
    ],
];

Usage

The package provides a SitemapService that handles sitemap generation and caching:

use Daikazu\Sitemap\Services\SitemapService;

$sitemapService = app(SitemapService::class);

// Generate sitemap if due (respects cooldown period)
$sitemapService->generateIfDue();

// Force regenerate sitemap regardless of cooldown
$sitemapService->forceRegenerate();

// Get the sitemap content
$sitemapContent = $sitemapService->getSitemapContent();

The package automatically handles scheduling of sitemap generation based on your configuration settings. You can customize the scheduling behavior through the config file.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.