From ea76386585cf38f04f277aa9db38081393dab9a5 Mon Sep 17 00:00:00 2001 From: timur Date: Sat, 17 Feb 2018 09:31:50 +0200 Subject: [PATCH] seo hreflang and sitemap --- backend/config/main.php | 29 +++++++++++++++++++++++++++-- common/components/Sitemap.php | 1 + common/config/SitemapDynamic.php | 26 +++++++++++++++++++++++--- common/config/SitemapStatic.php | 23 ++++++++++++++++++++--- frontend/views/layouts/main.php | 4 ++++ frontend/views/site/index.php | 12 ++++++++++-- frontend/views/site/media-about.php | 12 ++++++++++-- frontend/widgets/HreflangWidget.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 157 insertions(+), 12 deletions(-) mode change 100644 => 100755 common/config/SitemapDynamic.php mode change 100644 => 100755 common/config/SitemapStatic.php create mode 100644 frontend/widgets/HreflangWidget.php diff --git a/backend/config/main.php b/backend/config/main.php index 2bbc0cc..638d12e 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -2,6 +2,8 @@ use artbox\core\components\SeoUrlManager; use artbox\core\models\Page; use common\components\Sitemap; + use artbox\weblog\models\Article; + use common\models\Objectkb; $params = array_merge( require( __DIR__ . '/../../common/config/params.php' ), @@ -94,15 +96,38 @@ ], 'urlManagerFrontend' => [ 'class' => SeoUrlManager::className(), - 'baseUrl' => '/', 'enablePrettyUrl' => true, 'showScriptName' => false, - 'rules' => [], + // 'dontShowDefaulPrefix' => true, + 'rules' => [ + '\/robots.txt' => 'site/robots', + ], + 'processRoutes' => [ + 'object/view', + 'blog/article', + 'blog/tag', + 'blog/category', + 'page/view', + ], ], 'sitemap' => [ 'class' => Sitemap::className(), 'entities' => [ [ + 'class' => Objectkb::className(), + 'conditions' => [ + [ 'status' => 1 ], + ], + 'url' => 'object/view', + ], + [ + 'class' => Article::className(), + 'conditions' => [ + [ 'status' => 1 ], + ], + 'url' => 'blog/article', + ], + [ 'class' => Page::className(), 'conditions' => [ [ 'in_menu' => 1 ], diff --git a/common/components/Sitemap.php b/common/components/Sitemap.php index 64bf031..5bb1569 100644 --- a/common/components/Sitemap.php +++ b/common/components/Sitemap.php @@ -131,6 +131,7 @@ $urlManager->createAbsoluteUrl( [ $entity[ 'url' ], + 'alias' => $record->lang->alias, 'id' => $record->getAttribute('id'), ] ) diff --git a/common/config/SitemapDynamic.php b/common/config/SitemapDynamic.php old mode 100644 new mode 100755 index f02fbed..f7bba8c --- a/common/config/SitemapDynamic.php +++ b/common/config/SitemapDynamic.php @@ -1,5 +1,25 @@ [ + 'entity' => 'common\\models\\Objectkb', + 'status' => '1', + 'frequency' => 'daily', + 'priority' => '0.9', + 'id' => 1, + ], + 2 => [ + 'entity' => 'artbox\\weblog\\models\\Article', + 'status' => '1', + 'frequency' => 'weekly', + 'priority' => '0.8', + 'id' => 2, + ], + 3 => [ + 'entity' => 'artbox\\core\\models\\Page', + 'status' => '1', + 'frequency' => 'weekly', + 'priority' => '0.6', + 'id' => 3, + ], +]; \ No newline at end of file diff --git a/common/config/SitemapStatic.php b/common/config/SitemapStatic.php old mode 100644 new mode 100755 index f02fbed..30a430d --- a/common/config/SitemapStatic.php +++ b/common/config/SitemapStatic.php @@ -1,5 +1,22 @@ [ + 'url' => 'http://www.new-kbenergy.test', + 'frequency' => 'always', + 'priority' => '1', + 'id' => 1, + ], + 2 => [ + 'url' => 'http://www.new-kbenergy.test/ru/site/legal', + 'frequency' => 'daily', + 'priority' => '0.9', + 'id' => 2, + ], + 3 => [ + 'url' => 'http://www.new-kbenergy.test/ru/site/individual', + 'frequency' => 'daily', + 'priority' => '0.9', + 'id' => 3, + ], +]; \ No newline at end of file diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 7797c64..b136513 100644 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -23,6 +23,7 @@ use yii\web\View; use yii\widgets\Breadcrumbs; use common\models\Feedback; + use frontend\widgets\HreflangWidget; AppAsset::register($this); $user = \Yii::$app->user->identity; @@ -71,6 +72,9 @@ + + + <?= Html::encode($seo->title) ?> head() ?> diff --git a/frontend/views/site/index.php b/frontend/views/site/index.php index 99585e4..4af6a0c 100644 --- a/frontend/views/site/index.php +++ b/frontend/views/site/index.php @@ -409,13 +409,21 @@ JS;
- +
- +
diff --git a/frontend/views/site/media-about.php b/frontend/views/site/media-about.php index ac418a2..e3d82be 100644 --- a/frontend/views/site/media-about.php +++ b/frontend/views/site/media-about.php @@ -31,7 +31,11 @@ use yii\web\View;
- +
@@ -40,7 +44,11 @@ use yii\web\View;
- +
diff --git a/frontend/widgets/HreflangWidget.php b/frontend/widgets/HreflangWidget.php new file mode 100644 index 0000000..b58ad6f --- /dev/null +++ b/frontend/widgets/HreflangWidget.php @@ -0,0 +1,62 @@ +languages)){ + $this->languages = Language::getActive(); + } + + } + + public function run() + { + + foreach ($this->languages as $language){ + + ?> + + + +