Skip to content

Sitemap for Statamic v3

Notifications You must be signed in to change notification settings

visuellverstehen/sitemap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sitemap Addon for Statamic

Statamic 3.0+

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

Installation

Include the package with composer:

composer require pecotamic/sitemap

The package requires Laravel 7+ and PHP 7.3+. 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.

About

Sitemap for Statamic v3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 94.4%
  • Blade 5.6%