Skip to content

Commit

Permalink
Allow aliasing on {{ seo_pro:meta_data }} tag (#362)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
amadeann and jesseleite authored Dec 11, 2024
1 parent d17af1b commit d1ca00d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Directives/SeoProDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public function renderTag($tag, $context)
);
}

return $this->setContext($context)->$tag();
return $this
->setContext($context)
->setParameters([])
->$tag();
}

protected function isMissingContext($context)
Expand Down
2 changes: 1 addition & 1 deletion src/Tags/SeoProTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function metaData()
$metaData['is_twitter_glide_enabled'] = $this->isGlidePresetEnabled('seo_pro_twitter');
$metaData['is_og_glide_enabled'] = $this->isGlidePresetEnabled('seo_pro_og');

return $metaData;
return $this->aliasedResult($metaData);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/site/content/collections/pages/about.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
title: About
subtitle: The Best About Page
updated_by: 96300192-873c-4615-b992-157508a8d7c5
updated_at: 1579284102
template: page
id: 62136fa2-9e5c-4c38-a894-a2753f02f5ff
---
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.
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.
48 changes: 48 additions & 0 deletions tests/MetaTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,54 @@ public function it_hydrates_cascade_on_custom_routes_using_blade_directive($view
$this->assertStringContainsStringIgnoringLineEndings('<title>Custom Route Entry Title | Site Name</title>', $content);
}

/** @test */
public function it_can_loop_over_meta_data()
{
$this->withoutExceptionHandling();
$this->prepareViews('antlers');
$this->files->put(resource_path('views-seo-pro/layout.antlers.html'), <<<'EOT'
{{ seo_pro:meta_data }}
<h1>{{ title }}</h1>
<h2>{{ description }}</h2>
<h3>{{ canonical_url }}</h3>
{{ /seo_pro:meta_data }}
EOT);

$content = $this->get('/the-view')->content();
$this->assertStringContainsStringIgnoringLineEndings('<h1>The View</h1>', $content);
$this->assertStringContainsStringIgnoringLineEndings('<h2>A wonderful view!</h2>', $content);
$this->assertStringContainsStringIgnoringLineEndings('<h3>http://cool-runnings.com/the-view</h3>', $content);
}

/** @test */
public function it_can_loop_over_aliased_meta_data()
{
$this->withoutExceptionHandling();

$this
->prepareViews('antlers')
->setSeoOnCollection(Collection::find('pages'), [
'title' => '@seo:subtitle',
]);

$this->files->put(resource_path('views-seo-pro/layout.antlers.html'), <<<'EOT'
<h1 class="title_outside">{{ title }}</h1>
{{ seo_pro:meta_data as="foo" }}
<h1 class="title_inside">{{ title }}</h1>
<h1>{{ foo:title }}</h1>
<h3>{{ foo:canonical_url }}</h3>
<h3 class="canonical_url_without_scoping">{{ canonical_url }}</h3>
{{ /seo_pro:meta_data }}
EOT);

$content = $this->get('/about')->content();
$this->assertStringContainsStringIgnoringLineEndings('<h1 class="title_outside">About</h1>', $content);
$this->assertStringContainsStringIgnoringLineEndings('<h1 class="title_inside">About</h1>', $content);
$this->assertStringContainsStringIgnoringLineEndings('<h1>The Best About Page</h1>', $content);
$this->assertStringContainsStringIgnoringLineEndings('<h3>http://cool-runnings.com/about</h3>', $content);
$this->assertStringContainsStringIgnoringLineEndings('<h3 class="canonical_url_without_scoping"></h3>', $content);
}

protected function setCustomGlidePresetDimensions($app)
{
$app->config->set('statamic.seo-pro.assets', [
Expand Down

0 comments on commit d1ca00d

Please sign in to comment.