Skip to content

Commit d1ca00d

Browse files
amadeannjesseleite
andauthored
Allow aliasing on {{ seo_pro:meta_data }} tag (#362)
* Allow aliasing seo_pro:meta_data * Fix blade regression to pass failing blade tests. * Add basic test coverage for `meta_data` tag, with and without new `as` alias. --------- Co-authored-by: Jesse Leite <jesseleite@gmail.com>
1 parent d17af1b commit d1ca00d

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

src/Directives/SeoProDirective.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ public function renderTag($tag, $context)
1616
);
1717
}
1818

19-
return $this->setContext($context)->$tag();
19+
return $this
20+
->setContext($context)
21+
->setParameters([])
22+
->$tag();
2023
}
2124

2225
protected function isMissingContext($context)

src/Tags/SeoProTags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function metaData()
4949
$metaData['is_twitter_glide_enabled'] = $this->isGlidePresetEnabled('seo_pro_twitter');
5050
$metaData['is_og_glide_enabled'] = $this->isGlidePresetEnabled('seo_pro_og');
5151

52-
return $metaData;
52+
return $this->aliasedResult($metaData);
5353
}
5454

5555
/**
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
title: About
3+
subtitle: The Best About Page
34
updated_by: 96300192-873c-4615-b992-157508a8d7c5
45
updated_at: 1579284102
56
template: page
67
id: 62136fa2-9e5c-4c38-a894-a2753f02f5ff
78
---
8-
I'm just a kid living in the 90's, writing articles in his secret public journal wonder if someday, somewhere in the future, they will be read by someone.
9+
I'm just a kid living in the 90's, writing articles in his secret public journal wonder if someday, somewhere in the future, they will be read by someone.

tests/MetaTagTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,54 @@ public function it_hydrates_cascade_on_custom_routes_using_blade_directive($view
773773
$this->assertStringContainsStringIgnoringLineEndings('<title>Custom Route Entry Title | Site Name</title>', $content);
774774
}
775775

776+
/** @test */
777+
public function it_can_loop_over_meta_data()
778+
{
779+
$this->withoutExceptionHandling();
780+
$this->prepareViews('antlers');
781+
$this->files->put(resource_path('views-seo-pro/layout.antlers.html'), <<<'EOT'
782+
{{ seo_pro:meta_data }}
783+
<h1>{{ title }}</h1>
784+
<h2>{{ description }}</h2>
785+
<h3>{{ canonical_url }}</h3>
786+
{{ /seo_pro:meta_data }}
787+
EOT);
788+
789+
$content = $this->get('/the-view')->content();
790+
$this->assertStringContainsStringIgnoringLineEndings('<h1>The View</h1>', $content);
791+
$this->assertStringContainsStringIgnoringLineEndings('<h2>A wonderful view!</h2>', $content);
792+
$this->assertStringContainsStringIgnoringLineEndings('<h3>http://cool-runnings.com/the-view</h3>', $content);
793+
}
794+
795+
/** @test */
796+
public function it_can_loop_over_aliased_meta_data()
797+
{
798+
$this->withoutExceptionHandling();
799+
800+
$this
801+
->prepareViews('antlers')
802+
->setSeoOnCollection(Collection::find('pages'), [
803+
'title' => '@seo:subtitle',
804+
]);
805+
806+
$this->files->put(resource_path('views-seo-pro/layout.antlers.html'), <<<'EOT'
807+
<h1 class="title_outside">{{ title }}</h1>
808+
{{ seo_pro:meta_data as="foo" }}
809+
<h1 class="title_inside">{{ title }}</h1>
810+
<h1>{{ foo:title }}</h1>
811+
<h3>{{ foo:canonical_url }}</h3>
812+
<h3 class="canonical_url_without_scoping">{{ canonical_url }}</h3>
813+
{{ /seo_pro:meta_data }}
814+
EOT);
815+
816+
$content = $this->get('/about')->content();
817+
$this->assertStringContainsStringIgnoringLineEndings('<h1 class="title_outside">About</h1>', $content);
818+
$this->assertStringContainsStringIgnoringLineEndings('<h1 class="title_inside">About</h1>', $content);
819+
$this->assertStringContainsStringIgnoringLineEndings('<h1>The Best About Page</h1>', $content);
820+
$this->assertStringContainsStringIgnoringLineEndings('<h3>http://cool-runnings.com/about</h3>', $content);
821+
$this->assertStringContainsStringIgnoringLineEndings('<h3 class="canonical_url_without_scoping"></h3>', $content);
822+
}
823+
776824
protected function setCustomGlidePresetDimensions($app)
777825
{
778826
$app->config->set('statamic.seo-pro.assets', [

0 commit comments

Comments
 (0)