Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/becklyn/schema-org
A Symfony bundle to render Schema.org compatible JSON-LD meta data
https://github.com/becklyn/schema-org
json-ld schema-org seo symfony symfony-bundle
Last synced: about 1 month ago
JSON representation
A Symfony bundle to render Schema.org compatible JSON-LD meta data
- Host: GitHub
- URL: https://github.com/becklyn/schema-org
- Owner: Becklyn
- License: bsd-3-clause
- Created: 2020-06-02T15:52:45.000Z (over 4 years ago)
- Default Branch: 1.x
- Last Pushed: 2022-02-17T15:56:08.000Z (almost 3 years ago)
- Last Synced: 2024-11-08T19:20:03.706Z (about 1 month ago)
- Topics: json-ld, schema-org, seo, symfony, symfony-bundle
- Language: PHP
- Size: 149 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Becklyn Schema.org Bundle
=========================This bundle provides a thin integration for rendering Schema.org-compatible JSON-LD meta data tags.
Creating a schema
=================Before you can render the meta data inside your templates, you need to implement a `SchemaBuilderInterface` for each entity type, that you want to generate a JSON-LD schema for.
An example `SchemaBuilderInterface` implementation would look like this, which would convert an `MyNewsArticle` into a Schema.org `Article`.
```php
use App\Entity\MyNewsArticle;
use Becklyn\SchemaOrg\Data\Article;
use Becklyn\SchemaOrg\Data\Organization;
use Becklyn\SchemaOrg\Data\SchemaOrgDataInterface;
use Becklyn\SchemaOrg\SchemaBuilder\SchemaBuilderInterface;class MyNewsSchemaBuilder implements SchemaBuilderInterface
{
/**
* @inheritDoc
*/
public function supports ($entity, ?string $usage = null, array $context = []) : bool
{
return $entity instanceof MyNewsArticle;
}/**
* @inheritDoc
*/
public function buildSchema ($entity, ?string $usage = null, array $context = []) : ?SchemaOrgDataInterface
{
\assert($entity instanceof MyNewsArticle);// Don't generate metadata for unpublished news
if (!$entity->isPublished())
{
return null;
}return (new Article())
->withEditor($entity->getAuthor())
->withAbout($entity->getTeaserText())
->withArticleBody($entity->getTextContent())
->withPublisher(
(new Organization())
->withName("Awesome Publisher")
->withEmail("[email protected]")
)
->withLicense("Creative Commons Attribution-ShareAlike 3.0")
;
}
}
```Render meta data tag
====================To render the JSON-LD meta data tag, call the Twig function `{{ schema_org_meta_data(myAppEntity) }}` and pass in an optional `usage` and `context` parameter,
if you need to tweak the output based on the current render context.