All Projects → zhelyabuzhsky → yii2-sitemap

zhelyabuzhsky / yii2-sitemap

Licence: GPL-3.0 License
A Yii2 extension to generate sitemap files for large web-sites in console

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-sitemap

Sitemap
Site map creation support
Stars: ✭ 59 (+90.32%)
Mutual labels:  sitemap, yii2-extension
yii2-facades
Facades for Yii 2
Stars: ✭ 21 (-32.26%)
Mutual labels:  yii2-extension
yii2-timezone
Timezone detector
Stars: ✭ 14 (-54.84%)
Mutual labels:  yii2-extension
filedb
ActiveRecord for static data definitions based on files
Stars: ✭ 72 (+132.26%)
Mutual labels:  yii2-extension
yii2-behaviors
Collection of useful behaviors for Yii Framework 2.0
Stars: ✭ 25 (-19.35%)
Mutual labels:  yii2-extension
sitemap-plugin
Sitemap Plugin for Sylius eCommerce platform
Stars: ✭ 68 (+119.35%)
Mutual labels:  sitemap
TrollHunter
Twitter Troll & Fake News Hunter - Crawls news websites and twitter to identify fake news
Stars: ✭ 38 (+22.58%)
Mutual labels:  sitemap
yii2-firebird
Firebird connector for Yii2 framework
Stars: ✭ 23 (-25.81%)
Mutual labels:  yii2-extension
yii2-star-rating
Star rating widget based on jQuery Raty
Stars: ✭ 16 (-48.39%)
Mutual labels:  yii2-extension
yii2-tinymce
Yii2 extension, tinymce wysiwyg editor
Stars: ✭ 16 (-48.39%)
Mutual labels:  yii2-extension
ar-dynattribute
Provide ActiveRecord dynamic attributes stored into the single field in serialized state
Stars: ✭ 43 (+38.71%)
Mutual labels:  yii2-extension
gatsby-blog-mdx
A ready-to-use, customizable personal blog with minimalist design
Stars: ✭ 61 (+96.77%)
Mutual labels:  sitemap
yii2-telegram
Support chat for site based on Telegram bot
Stars: ✭ 49 (+58.06%)
Mutual labels:  yii2-extension
sitemap-checker
a tool for validate xml sitemap and sitemap index files for broken links
Stars: ✭ 21 (-32.26%)
Mutual labels:  sitemap
sitewriter
A rust library to generate sitemaps.
Stars: ✭ 18 (-41.94%)
Mutual labels:  sitemap
yii2-payment
Yii2 Payment extension hổ trợ tích hợp các cổng thanh toán VnPayment, Onepay, Bảo Kim, Ngân Lượng, VTCPay, MoMo.
Stars: ✭ 20 (-35.48%)
Mutual labels:  yii2-extension
plugins
Elder.js plugins and community plugins.
Stars: ✭ 80 (+158.06%)
Mutual labels:  sitemap
yii2-merit
Reputation engine for Yii2 用于实现积分,等级功能的设计
Stars: ✭ 16 (-48.39%)
Mutual labels:  yii2-extension
yii2-jwt-user
JWT (JSON Web Token) User component for Yii 2
Stars: ✭ 16 (-48.39%)
Mutual labels:  yii2-extension
sitemap
A simple sitemap generator for Laravel Framework.
Stars: ✭ 32 (+3.23%)
Mutual labels:  sitemap

Sitemap.xml generator for Yii2

Build Status Total Downloads

Yii2 extension to generate sitemap files for large web-sites through Yii2 console command

Installation

The preferred way to install this extension is through composer.

$ php composer.phar require zhelyabuzhsky/yii2-sitemap

or add

"zhelyabuzhsky/yii2-sitemap": "^1.1"

to the require section of your composer.json file.

Features

  • Generates multiple sitemaps (large sites)
  • Creates index sitemap file
  • Gzip compression of .xml files
  • Disallow urls support (through regular expression array)

Configuration

1. Configure urlManager at console config

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

NOTE Both params hostInfo and baseUrl are required for Yii2 console app.

NOTE urlManager rules section usually repeats your frontend urlManager configuration, so you could merge it at console config (see https://github.com/yiisoft/yii2/issues/1578#issuecomment-66716648):

Show details

console/main.php

$frontendUrlManager = require(__DIR__ . '/../../frontend/config/UrlManager.php');
//...
'urlManager' => array_merge($frontendUrlManager, [
    'hostInfo' => 'https://example.com'
]),

frontend/config/UrlManager.php

<?php
return [
    'baseUrl' => '/',
    'class' => 'yii\web\UrlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
      //...
    ],
];

?>

2. Configure Sitemap component at console config components section

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

Example of using extra Sitemap params

'components' => [
  '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.

Usage

1. Impement SitemapEntityInterface for the models you want to use at sitemap

Show example

common\models\Category.php

use yii\db\ActiveRecord;
use zhelyabuzhsky\sitemap\models\SitemapEntityInterface;

class Category extends ActiveRecord implements SitemapEntityInterface
{
    /**
     * @inheritdoc
     */
    public function getSitemapLastmod()
    {
        return date('c');
    }
    /**
     * @inheritdoc
     */
    public function getSitemapChangefreq()
    {
        return 'daily';
    }
    /**
     * @inheritdoc
     */
    public function getSitemapPriority()
    {
        return 0.5;
    }
    /**
     * @inheritdoc
     */
    public function getSitemapLoc()
    {
        // Use urlManager rules to create urls
        return $url = Yii::$app->urlManager->createAbsoluteUrl([
            'page/view',
            'pageSlug' => $this->slug,
        ]);
        // or directly
        // return 'http://localhost/' . $this->slug;
    }
    /**
     * @inheritdoc
     */
    public static function getSitemapDataSource()
    {
        return self::find();
    }
}

2. Create Yii2 controller for console command

use yii\console\Controller;

class SitemapController extends Controller
{
  public function actionCreate()
  {
    \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();
    }
}

3. Run console command

php yii sitemap/create

Testing

Set enviroment variable SERVER_NAME (e.g. https://example.com)

$ ./vendor/bin/phpunit

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].