pecotamic/sitemap

Simple sitemap addon for Statamic v3

Installs: 96 358

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 2

Forks: 9

Open Issues: 0

Type:statamic-addon

1.4.7 2024-05-09 22:00 UTC

This package is auto-updated.

Last update: 2024-11-09 23:03:17 UTC


README

Statamic 3.0+ Statamic 4.0+ Statamic 5.0+

Automatically adds a sitemap to your Statamic web site. The default path is <your web site>/sitemap.xml

Installation

Include the package with composer:

composer require pecotamic/sitemap

The package requires PHP 7.3+ or PHP 8+. It will auto register.

Configuration (optional)

You can override the default options by publishing the configuration:

php artisan vendor:publish --provider="Pecotamic\Sitemap\ServiceProvider" --tag=config

This will copy the default config file to config/pecotamic/sitemap.php.

View (optional)

You can also override the view template to adjust the output by publishing the view:

php artisan vendor:publish --provider="Pecotamic\Sitemap\ServiceProvider" --tag=view

The view template will be copied to resources/views/vendor/pecotamic/sitemap/sitemap.blade.php.

If you prefer another view engine, it is also possible. For example to use Antlers, create a file named sitemap.antlers.html instead of the blade template.

View variables

An array of sitemap entries is passed to the view template. Each entry has these properties:

  • loc: The absolute url
  • path: The relative path
  • lastmod: A DateTime object of the last modification date
  • changefreq: A string like 'daily', 'weekly' (optional)
  • priority: A string presenting a float value between 0 and 1 (optional)

Dynamically adding entries (optional)

You may add entries dynamically by providing a closure that returns an array to the addEntries method.

use Pecotamic\Sitemap\Sitemap;
use Pecotamic\Sitemap\SitemapEntry;

class AppServiceProvider extends Provider
{
    public function boot()
    {
        Sitemap::addEntries(static function () {
            return [
                new SitemapEntry('/hidden-page', new \DateTime('2020-02-20')),
                new SitemapEntry('/about-me', new \DateTime('now'), 'daily', '1.0'),
            ];
        });
    }
}

Credits

Thanks for code contribution to Prageeth Silva and Poh Nean.