vaersaagod / seomate

SEO, mate! It's important. That's why SEOMate provides the tools you need to craft all the meta tags, sitemaps and JSON-LD microdata you need - in one highly configurable, open and friendly package - with a super-light footprint.
MIT License
36 stars 8 forks source link

Are JSON-LD graphs available? #70

Closed vanburenx closed 1 year ago

vanburenx commented 1 year ago

I'm submitting a...

Description

Are **_JSON-LD graphs_** available? I know `spatie/schema-org` supports them but I haven't been able to determine if they're available in SEOMate or how to access them if they are. #### spatie/schema-org - [Graph - multiple items](https://github.com/spatie/schema-org/blob/111488e5110da30cc96b775b480bc29b28164883/README.md#graph---multiple-items) - [Graph.php](https://github.com/spatie/schema-org/blob/main/src/Graph.php) Thanks for any assistance and for this great plugin in general! ### JSON-LD graph Example ``` { "@context": "https://schema.org", "@graph": [{ "@type": "Article", "@id": "https://example.com/blog/blog-post/#article", "name": "It's A WebSite!", "headline": "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum", "author": { "@id": "https://example.com/author/author-name/#author" }, "publisher": { "@id": "https://example.com/#organization" }, "image": { "@type": "ImageObject", "url": "https://example.com/images/.jpg", "width": 1920, "height": 1080 }, "datePublished": "2023-05-01T22:18:17-08:00", "dateModified": "2023-05-01T22:18:17-08:00", "inLanguage": "en-US", "mainEntityOfPage": { "@id": "https://example.com/blog/blog-post/#webpage" }, "isPartOf": { "@id": "https://example.com/blog/blog-post/#webpage" }, "articleSection": "Somewhere, Something" }, { "@type": "BreadcrumbList", "@id": "https://example.com/blog/blog-post/#breadcrumblist", "itemListElement": [{ "@type": "ListItem", "@id": "https://example.com/#listItem", "position": 1, "item": { "@type": "WebPage", "@id": "https://example.com/", "name": "Home", "description": "Dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "url": "https://example.com/" }, "nextItem": "https://example.com/blog/blog-post/#listItem" }, { "@type": "ListItem", "@id": "https://example.com/blog/blog-post/#listItem", "position": 2, "item": { "@type": "WebPage", "@id": "https://example.com/blog/blog-post/", "name": "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam", "url": "https://example.com/blog/blog-post/" }, "previousItem": "https://example.com/#listItem" }] }, { "@type": "Organization", "@id": "https://example.com/#organization", "name": "It's A WebSite", "url": "https://example.com/", "logo": { "@type": "ImageObject", "url": "https://example.com/images/logo.png", "@id": "https://example.com/#organizationLogo", "width": 200, "height": 50 }, "image": { "@id": "https://example.com/#organizationLogo" } }, { "@type": "Person", "@id": "https://example.com/author/author-name/#author", "url": "https://example.com/author/author-name/", "name": "Author Name", "image": { "@type": "ImageObject", "@id": "https://example.com/blog/blog-post/#authorImage", "url": "https://example.com/images/icon.png", "width": 96, "height": 96, "caption": "Author Name" } }, { "@type": "WebPage", "@id": "https://example.com/blog/blog-post/#webpage", "url": "https://example.com/blog/blog-post/", "name": "It's A WebSite!", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam", "inLanguage": "en-US", "isPartOf": { "@id": "https://example.com/#website" }, "breadcrumb": { "@id": "https://example.com/blog/blog-post/#breadcrumblist" }, "author": { "@id": "https://example.com/author/author-name/#author" }, "creator": { "@id": "https://example.com/author/author-name/#author" }, "image": { "@type": "ImageObject", "url": "https://example.com/images/.jpg", "@id": "https://example.com/#mainImage", "width": 2560, "height": 1920 }, "primaryImageOfPage": { "@id": "https://example.com/blog/blog-post/#mainImage" }, "datePublished": "2023-05-01T22:18:17-08:00", "dateModified": "2023-05-01T22:18:17-08:00" }, { "@type": "WebSite", "@id": "https://example.com/#website", "url": "https://example.com/", "name": "It's A WebSite!", "description": "Sed odio morbi quis commodo odio.", "inLanguage": "en-US", "publisher": { "@id": "https://example.com/#organization" } }] } ``` ### Additional info - SEOmate version: 2.1.1 - Craft CMS version: 4.4.9 - PHP version: 8.0.28 - Operating system and version: Linux 5.10.177-158.645.amzn2.x86_64 - Database type and version: PostgreSQL 14.7 - Image driver and version: Imagick 3.7.0 (ImageMagick 7.1.1-9)
mmikkel commented 1 year ago

Hi, sorry for the late response on this.

For JSON-LD, SEOMate provides a thin wrapper around the spatie/schema-org package (via the craft.schema variable). From what I can tell, the schema-org package does support JSON-LD graphs, but unlike the schema types there is no factory method for it.

Basically, you need to create a new Graph instance using the create() Twig function, and then add schema types to it:

{# @var graph Spatie\\SchemaOrg\\Graph #}
{% set graph = create('Spatie\\SchemaOrg\\Graph') %}

{% do graph.article()
    .name('It\'s a website!')
    ...
%}

{{ graph|raw }}