A Yii2 extension to generate sitemap files for large web-sites in console
Via Composer
$ composer require zhelyabuzhsky/yii2-sitemap
- multiple sitemaps (large sites)
- index sitemap
- gzip
- disallow urls (regular expression array)
'sitemap' =>
[
'class' => '\zhelyabuzhsky\sitemap\components\Sitemap',
],
'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.
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();
}
$ ./vendor/bin/phpunit
If you discover any security related issues, please email zhelyabuzhsky@icloud.com instead of using the issue tracker.
GNU General Public License, version 3. Please see License File for more information.