2017 © Pedro Peláez
 

yii2-extension yii2-sitemap-module

Yii2 module for automatically generation XML Sitemap

image

assayer-pro/yii2-sitemap-module

Yii2 module for automatically generation XML Sitemap

  • Saturday, December 16, 2017
  • by assayer-pro
  • Repository
  • 3 Watchers
  • 5 Stars
  • 2,001 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 37 Forks
  • 1 Open issues
  • 14 Versions
  • 15 % Grown

The README.md

XML Sitemap Module for Yii2

PHP version Scrutinizer Code Quality Code Coverage Build Status, (*1)

Yii2 module for automatically generating XML Sitemap., (*2)

Installation

The preferred way to install this extension is through composer., (*3)

  • Either run
php composer.phar require --prefer-dist "assayer-pro/yii2-sitemap-module" "*"

or add, (*4)

"assayer-pro/yii2-sitemap-module" : "*"

to the require section of your application's composer.json file., (*5)

  • Configure the cache component of your application's configuration file, for example:
'components' => [
    'cache' => [
        'class' => 'yii\caching\FileCache',
    ],
]
  • Add a new module in modules section of your application's configuration file, for example:
'modules' => [
    'sitemap' => [
        'class' => 'assayerpro\sitemap\Module',
    ],
...
],
  • Add confuguration for sitemap into components section:
'components' => [
    'robotsTxt' => [
        'class' => 'assayerpro\sitemap\RobotsTxt',
        'userAgent' => [
            // Disallow url for all bots
            '*' => [
                'Disallow' => [
                    ['/api/default/index'],
                ],
                'Allow' => [
                    ['/api/doc/index'],
                ],
            ],
            // Block a specific image from Google Images
            'Googlebot-Image' => [
                'Disallow' => [
                    // All images on your site from Google Images
                    '/',
                    // Files of a specific file type (for example, .gif)
                    '/*.gif$',
                ],
            ],
        ],
    ],
    'sitemap' => [
        'class' => 'assayerpro\sitemap\Sitemap',
        'models' => [
            // your models
            'app\modules\news\models\News',
            // or configuration for creating a behavior
            [
                'class' => 'app\modules\news\models\News',
                'behaviors' => [
                    'sitemap' => [
                        'class' => '\assayerpro\sitemap\behaviors\SitemapBehavior',
                        'scope' => function ($model) {
                            /** @var \yii\db\ActiveQuery $model */
                            $model->select(['url', 'lastmod']);
                            $model->andWhere(['is_deleted' => 0]);
                        },
                        'dataClosure' => function ($model) {
                            /** @var self $model */
                            return [
                                'loc' => Url::to($model->url, true),
                                'lastmod' => strtotime($model->lastmod),
                                'changefreq' => \assayerpro\sitemap\Sitemap::DAILY,
                                'priority' => 0.8
                            ];
                        }
                    ],
                ],
            ],
        ],
        'urls'=> [
            // your additional urls
            [
                'loc' => ['/news/default/index'],
                'changefreq' => \assayerpro\sitemap\Sitemap::DAILY,
                'priority' => 0.8,
                'news' => [
                    'publication'   => [
                        'name'          => 'Example Blog',
                        'language'      => 'en',
                    ],
                    'access'            => 'Subscription',
                    'genres'            => 'Blog, UserGenerated',
                    'publication_date'  => 'YYYY-MM-DDThh:mm:ssTZD',
                    'title'             => 'Example Title',
                    'keywords'          => 'example, keywords, comma-separated',
                    'stock_tickers'     => 'NASDAQ:A, NASDAQ:B',
                ],
                'images' => [
                    [
                        'loc'           => 'http://example.com/image.jpg',
                        'caption'       => 'This is an example of a caption of an image',
                        'geo_location'  => 'City, State',
                        'title'         => 'Example image',
                        'license'       => 'http://example.com/license',
                    ],
                ],
            ],
        ],
        'enableGzip' => true, // default is false
        'cacheExpire' => 1, // 1 second. Default is 24 hours,
        'sortByPriority' => true, // default is false
    ],
],
  • Add behavior in the AR models, for example:
use assayerpro\sitemap\behaviors\SitemapBehavior;

public function behaviors()
{
    return [
        'sitemap' => [
            'class' => SitemapBehavior::className(),
            /**'batchSize' => 100,*/
            'scope' => function ($model) {
                /** @var \yii\db\ActiveQuery $model */
                $model->select(['url', 'lastmod']);
                $model->andWhere(['is_deleted' => 0]);
            },
            'dataClosure' => function ($model) {
                /** @var self $model */
                return [
                    'loc' => Url::to($model->url, true),
                    'lastmod' => strtotime($model->lastmod),
                    'changefreq' => Sitemap::DAILY,
                    'priority' => 0.8
                ];
            }
        ],
    ];
}
  • Add a new rule for urlManager of your application's configuration file, for example:
'urlManager' => [
    'rules' => [
        ['pattern' => 'sitemap-<id:\d+>', 'route' => '/sitemap/default/index', 'suffix' => '.xml'],
        ['pattern' => 'sitemap', 'route' => 'sitemap/default/index', 'suffix' => '.xml'],
    ],
],

Console generate sitemap

Remove sitemap section from modules configuration., (*6)

Add console command configuration:, (*7)

    'controllerMap' => [
        'sitemap' => [
            'class' => 'assayerpro\sitemap\console\CreateController',
        ],
    ],

Add baseUrl for urlManager:, (*8)

     'urlManager' => [
         'baseUrl' => '',
         'hostInfo' => 'http://example.com/',
     ],

Run command from console:, (*9)

$ ./yii sitemap/create

Resources

The Versions

16/12 2017

dev-develop

dev-develop

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

12/12 2017

dev-master

9999999-dev

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

12/12 2017

1.3.6

1.3.6.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

12/12 2017

1.3.5

1.3.5.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

27/10 2017

1.3.4

1.3.4.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

23/05 2016

1.3.3

1.3.3.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

11/11 2015

1.3.2

1.3.2.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

05/11 2015

1.3.1

1.3.1.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

05/11 2015

1.3.0

1.3.0.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

The Development Requires

xml yii2 module sitemap

01/10 2015

1.2.1

1.2.1.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap

28/09 2015

1.2.0

1.2.0.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap

26/01 2015

1.1.1

1.1.1.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap

07/12 2014

1.1.0

1.1.0.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap

29/09 2014

1.0.0

1.0.0.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap