Skip to content

Commit

Permalink
Merge branch 'dev-4' of github.com:baserproject/basercms into dev-4
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Jun 10, 2024
2 parents 0dff8b8 + 2b1c467 commit 87f2ce7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Baser/Test/Case/View/Helper/BcBaserHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2381,8 +2381,11 @@ public function setAlternateUrlDataProvider()
* testSetAlternateUrl
* @dataProvider setCanonicalUrlDataProvider
*/
public function testSetCanonicalUrl($url, $expected)
public function testSetCanonicalUrl($url, $expected, $canonicalUrl = null)
{
if (!is_null($canonicalUrl)) {
$this->_View->set('canonicalUrl', $canonicalUrl);
}
Configure::write('BcSite.use_site_device_setting', true);
$this->BcBaser->request = $this->_getRequest($url);
$this->BcBaser->setCanonicalUrl();
Expand All @@ -2396,6 +2399,8 @@ public function setCanonicalUrlDataProvider()
['/index.html', '<link href="http://localhost/" rel="canonical"/>'],
['/about/index.html', '<link href="http://localhost/about/" rel="canonical"/>'],
['/s/', '<link href="http://localhost/" rel="canonical"/>'],
['/', '<link href="https://example.com" rel="canonical"/>', 'https://example.com'],
['/', '', false],
];
}
}
17 changes: 17 additions & 0 deletions lib/Baser/View/Helper/BcBaserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,23 @@ public function afterRender($viewFile)
* - PCサイトが存在する場合、canonicalを出力
*/
public function setCanonicalUrl() {
$canonicalUrl = $this->_View->get('canonicalUrl');
if ($canonicalUrl === false) {
return;
}
if ($canonicalUrl) {
return $this->_View->set('meta',
$this->BcHtml->meta('canonical',
$this->BcHtml->url($canonicalUrl, true),
[
'rel' => 'canonical',
'type' => null,
'title' => null,
'inline' => false
]
)
);
}
$currentSite = BcSite::findCurrent();
if (!$currentSite) {
return;
Expand Down

0 comments on commit 87f2ce7

Please sign in to comment.