Skip to content

Commit

Permalink
Schema.org improvements
Browse files Browse the repository at this point in the history
Allow Block `schemaOrg()` to return null so logic can be added
Limit depth of components to check for schema to stop everything being returned
Configure with: `storyblok.schema_org_depth`
  • Loading branch information
Richard Le Poidevin committed Aug 3, 2023
1 parent 74435cb commit ead2a0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 11 additions & 0 deletions config/storyblok.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,15 @@
|
*/
'date_format' => 'H:i:s j F Y',

/*
|--------------------------------------------------------------------------
| How deep to go when creating page schema.org data
|--------------------------------------------------------------------------
|
| As you may be nesting many blocks and linking to other stories, this
| you may want to limit the depth of the schema.org data returned
|
*/
'schema_org_depth' => 5,
];
12 changes: 7 additions & 5 deletions src/Traits/SchemaOrg.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ protected function initSchemaOrg(): void
$page = $this->page();
}

if ($page) {
$this->add($page);
if ($page && count($this->_componentPath) <= config('storyblok.schema_org_depth')) {
$this->addschemaOrg($page);
}
}

Expand All @@ -48,12 +48,14 @@ public function schemaOrgScript(): string
*
* @param $page
*/
private function add($page): void
protected function addschemaOrg($page): void
{
$currentSchemaOrg = $page->meta('schema_org');

$currentSchemaOrg[] = $this->schemaOrg();
if ($schema = $this->schemaOrg()) {
$currentSchemaOrg[] = $schema;
}

$page->replaceMeta('schema_org', $currentSchemaOrg ?? []);
}
}
}

0 comments on commit ead2a0c

Please sign in to comment.