Skip to content
Permalink
Browse files

Add sitemap.xml

  • Loading branch information...
dignityinside committed Aug 21, 2018
1 parent f491e09 commit b80850840d15462e52d9411a37e80e9839c0c4b5
Showing with 107 additions and 7 deletions.
  1. +3 −0 .gitignore
  2. +6 −0 README.md
  3. +2 −1 composer.json
  4. +17 −3 config/console.php-distr
  5. +2 −3 config/web.php-distr
  6. +77 −0 models/sitemap/SitemapPost.php
@@ -17,6 +17,9 @@ Thumbs.db
/rbac/items.php
/rbac/rules.php

# ignore generated sitemaps files
/web/sitemap*.xml

# ignore uploads and legacy folders
/web/uploads
/web/wp-content
@@ -52,6 +52,12 @@ php yii rbac/assign admin dignity
php yii rbac/assign moderator dignity
```

## Generate sitemap.xml

```
php yii sitemap
```

## License
This project is licensed under the MIT License. See the LICENSE file for details.

@@ -20,7 +20,8 @@
"bower-asset/codemirror": "~5.9.0",
"bower-asset/codemirror-buttons": "~1.0.0",
"dignityinside/translithelper": "^0.0.1",
"kartik-v/yii2-widget-select2": "^2.1"
"kartik-v/yii2-widget-select2": "^2.1",
"demi/sitemap-generator": "~1.0"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
@@ -1,7 +1,11 @@
<?php

$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');
$web = require(__DIR__ . '/web.php');

$config = [
'id' => 'basic-console',
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'app\commands',
@@ -17,12 +21,22 @@ $config = [
],
],
],
'db' => require(__DIR__ . '/db.php'),
'db' => $db,
'authManager' => [
'class' => 'yii\rbac\PhpManager',
],
'urlManager' => $web['components']['urlManager'],
],
'params' => $params,
'controllerMap' => [
'sitemap' => [
'class' => 'demi\sitemap\SitemapController',
'modelsPath' => '@app/models/sitemap',
'modelsNamespace' => 'app\models\sitemap',
'savePathAlias' => 'web',
'sitemapFileName' => 'sitemap.xml'
],
],
'params' => require(__DIR__ . '/params.php'),
];

if (YII_ENV_DEV) {
@@ -10,9 +10,7 @@ $config = [
],
'defaultRoute' => 'post/index',
'language' => 'ru-RU',
'bootstrap' => [
'log'
],
'bootstrap' => ['log'],
'components' => [
'authManager' => [
'class' => 'yii\rbac\PhpManager',
@@ -70,6 +68,7 @@ $config = [
'class' => 'app\components\PostUrlRule',
]
],
'baseUrl' => 'https://phpland.org',
],
'comment' => require(__DIR__ . '/comments.php'),
],
@@ -0,0 +1,77 @@
<?php
namespace app\models\sitemap;
use yii\helpers\Url;
use app\models\Post;
use demi\sitemap\interfaces\Basic;
/**
* Class SitemapPost
*
* @author Alexander Schilling
*
* @package app\models\sitemap
*/
class SitemapPost extends Post implements Basic
{
/**
* @inheritdoc
*/
public function getSitemapItems($lang = null)
{
return [
// post/index
[
'loc' => Url::to(['/post/index']),
'lastmod' => time(),
'changefreq' => static::CHANGEFREQ_DAILY,
'priority' => static::PRIORITY_10
],
];
}
/**
* @inheritdoc
*/
public function getSitemapItemsQuery($lang = null)
{
return static::find()
->select(['title', 'datecreate', 'dateupdate', 'slug'])
->where(['status_id' => Post::STATUS_PUBLIC])
->orderBy(['datecreate' => SORT_DESC]);
}
/**
* @inheritdoc
*/
public function getSitemapLoc($lang = null)
{
return Url::to(['/post/view', 'slug' => $this->slug], true);
}
/**
* @inheritdoc
*/
public function getSitemapLastmod($lang = null)
{
return $this->dateupdate;
}
/**
* @inheritdoc
*/
public function getSitemapChangefreq($lang = null)
{
return static::CHANGEFREQ_MONTHLY;
}
/**
* @inheritdoc
*/
public function getSitemapPriority($lang = null)
{
return static::PRIORITY_8;
}
}

0 comments on commit b808508

Please sign in to comment.
You can’t perform that action at this time.