Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEO関連メタタグの設定 #4987

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Eccube/Resource/template/default/default_frame.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ file that was distributed with this source code.
<title>{{ BaseInfo.shop_name }}{% if subtitle is defined and subtitle is not empty %} / {{ subtitle }}{% elseif title is defined and title is not empty %} / {{ title }}{% endif %}</title>
{% if Page.meta_tags is not empty %}
{{ include(template_from_string(Page.meta_tags)) }}
{% if Page.description is not empty %}
<meta name="description" content="{{ Page.description }}">
{% endif %}
{% else %}
{{ include('meta.twig') }}
{% endif %}
{% if Page.author is not empty %}
<meta name="author" content="{{ Page.author }}">
{% endif %}
{% if Page.description is not empty %}
<meta name="description" content="{{ Page.description }}">
{% endif %}
{% if Page.keyword is not empty %}
<meta name="keywords" content="{{ Page.keyword }}">
{% endif %}
Expand Down
18 changes: 9 additions & 9 deletions src/Eccube/Resource/template/default/meta.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if Product is defined %}
{% if app.request.get('_route') == 'product_detail' %}
{% set meta_og_type = "og:product" %}
{% set meta_description = Product.description_list | default(Product.description_detail) | default(Page.description) %}
{% set meta_canonical = url('product_detail', {'id': Product.id}) %}
Expand All @@ -8,17 +8,17 @@
<meta property="product:price:currency" content="{{ eccube_config.currency }}"/>
<meta property="product:product_link" content="{{ url('product_detail', {'id': Product.id}) }}"/>
<meta property="product:retailer_title" content="{{ BaseInfo.shop_name }}"/>
{% elseif Category is defined %}
{% set meta_og_type = 'article' %}
{% set meta_description = Page.description %}
{% elseif app.request.get('_route') == 'product_list' %}
{% set meta_canonical = url('product_list', {'category_id': Category.id|default(null)}) %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

検索キーワードは含めないでよいですか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「検索キーワード」は管理画面で入力する meta keyword のことでしょうか、であれば従来どおり default_frame.twig で出力しており、今回は変更していません

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matsuoshi
フロントでのキーワード検索を行った際のcanonicalとog:urlですね。
同じcategory_idでもキーワード検索が入ると結果が変わってくるので
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chihiro-adachi はい、ここは意図したのもでして、一覧ページでは検索クエリ、ページ番号、orderby などは canonical に含めないようにしています
(カテゴリID以外のパラメタを canonical には指定せず、パラメタ違いで別ページと認識されるのを防ぐ)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。了解しました。

{% elseif Page is defined %}
{% set meta_og_type = (app.request.get('_route') == 'homepage') ? 'website' : 'article' %}
{% set meta_description = Page.description %}
{% elseif app.request.get('_route') == 'homepage' %}
{% set meta_og_type = 'website' %}
{% set meta_canonical = url('homepage') %}
{% endif %}
<meta property="og:type" content="{{ meta_og_type }}"/>

<meta property="og:type" content="{{ meta_og_type|default('article') }}"/>
<meta property="og:site_name" content="{{ BaseInfo.shop_name }}"/>
{% if meta_description|default() %}
{% set meta_description = meta_description | default(Page.description) %}
{% if meta_description %}
<meta name="description" content="{{ meta_description|striptags|slice(0,120) }}">
<meta property="og:description" content="{{ meta_description|striptags|slice(0,120) }}"/>
{% endif %}
Expand Down
11 changes: 8 additions & 3 deletions tests/Eccube/Tests/Web/TopControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

namespace Eccube\Tests\Web;

use Eccube\Entity\BaseInfo;
use Eccube\Entity\Page;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\PageRepository;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class TopControllerTest extends AbstractWebTestCase
{
Expand All @@ -39,11 +40,15 @@ public function testMetaTags()
{
// description を設定
$description = 'あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモリーオ市、郊外のぎらぎらひかる草の波。';
$page = $this->container->get(PageRepository::class)->getByUrl('homepage');
/** @var PageRepository $pageRepository */
$pageRepository = $this->entityManager->getRepository(Page::class);
$page = $pageRepository->getByUrl('homepage');
$page->setDescription($description);
$this->entityManager->flush();

$shopName = $this->container->get(BaseInfoRepository::class)->get()->getShopName();
/** @var BaseInfoRepository $baseInfoRepository */
$baseInfoRepository = $this->entityManager->getRepository(BaseInfo::class);
$shopName = $baseInfoRepository->get()->getShopName();
$expected_desc = mb_substr($description, 0, 120, 'utf-8');

$crawler = $this->client->request('GET', $this->generateUrl('homepage'));
Expand Down