/yii2-sitemap

A Yii2 extension to generate sitemap files for large web-sites in console

Primary LanguagePHPGNU General Public License v3.0GPL-3.0

yii2-sitemap

Build Status Total Downloads

A Yii2 extension to generate sitemap files for large web-sites in console

Install

Via Composer

$ composer require zhelyabuzhsky/yii2-sitemap

Features

  • multiple sitemaps (large sites)
  • index sitemap
  • gzip
  • disallow urls (regular expression array)

Usage

Basic initialization

'sitemap' =>
  [
    'class' => '\zhelyabuzhsky\sitemap\components\Sitemap',
  ],

Advanced initialization

'sitemap' =>
  [
    'class' => '\zhelyabuzhsky\sitemap\components\Sitemap',
    'maxUrlsCountInFile' => 10000,
    'sitemapDirectory' => 'frontend/web',
    'optionalAttributes' => ['changefreq', 'lastmod', 'priority'],
    'maxFileSize' => '10M',
  ],

where

  • maxUrlsCountInFile - max count of urls in one sitemap file;
  • sitemapDirectory - directory to place sitemap files;
  • optionalAttributes - list of used optional attributes;
  • maxFileSize - maximal file size. Zero to work without limits. So you can specify the following abbreviations k - kilobytes and m - megabytes. By default 10m.

Console action

public function actionCreateSitemap()
{
  \Yii::$app->sitemap
    ->addModel(Item::className())
    ->addModel(Category::className(), \Yii::$app->db) // Also you can pass \yii\db\Connection to the database connection that you need to use
    ->setDisallowUrls([
      '#url1#',
      '#url2$#',
    ])
    ->create();
}

Testing

$ ./vendor/bin/phpunit

Security

If you discover any security related issues, please email zhelyabuzhsky@icloud.com instead of using the issue tracker.

Credits

License

GNU General Public License, version 3. Please see License File for more information.