Features
JSON-LD in Prezet
Prezet automatically generates JSON-LD to enhance your site's structured data, improving visibility on search engines and social media. By default, Prezet includes metadata such as your article's headline, publishing date, and author information following the Google Article Guide.
#How It Works
- Front Matter: Prezet extracts key information—like
title
,date
,excerpt
,image
, andauthor
—from your front matter. - Linked Data Action: This data is then passed through the
GetLinkedData
action, which compiles your post’s structured data in a JSON-LD format. - Blade Template: The JSON-LD is injected into the
<head>
section inresources/views/vendor/prezet/show.blade.php
via a simple script tag.
Below is a snippet from the default show.blade.php
that demonstrates how the JSON-LD is loaded:
1{{-- show.blade.php --}}2@push('jsonld')3 <script type="application/ld+json">{!! $linkedData !!}</script>4@endpush
#Default JSON-LD Output
Out of the box, the JSON-LD includes:
- Article Title (
headline
): Pulled from thetitle
in front matter. - Publication Date (
datePublished
): Derived from the front matterdate
or file modification date. - Modified Date (
dateModified
): Reflects when the document was last updated. - Author (
author
): Controlled by your front matter and the'authors'
array inconfig/prezet.php
. - Publisher (
publisher
): Defined in the'publisher'
array ofconfig/prezet.php
. - Image (
image
): Uses the front matterimage
field if set; otherwise defaults to your publisher'simage
.
Here is an example of what the JSON-LD might look like in your rendered HTML:
1{ 2 "@context": "https://schema.org", 3 "@type": "Article", 4 "headline": "My Awesome Blog Post", 5 "datePublished": "2024-06-30T12:00:00+00:00", 6 "dateModified": "2024-07-01T10:15:27+00:00", 7 "author": { 8 "@type": "Person", 9 "name": "Jane Doe",10 "url": "https://jane.example.com",11 "image": "https://jane.example.com/avatar.jpg"12 },13 "publisher": {14 "@type": "Organization",15 "name": "Prezet",16 "url": "https://prezet.com",17 "logo": "https://prezet.com/favicon.svg",18 "image": "https://prezet.com/ogimage.png"19 },20 "image": "https://jane.example.com/my-featured-image.webp"21}
#Customizing Your JSON-LD
#Front Matter & Author Fields
Prezet uses the front matter’s author
field to decide which author profile to link. If you’d like to store multiple author definitions (e.g., for a multi-author blog), add them to the 'authors'
array in config/prezet.php
:
1'authors' => [ 2 'jane_doe' => [ 3 '@type' => 'Person', 4 'name' => 'Jane Doe', 5 'url' => 'https://jane.example.com', 6 'image' => 'https://jane.example.com/avatar.jpg', 7 ], 8 'john_smith' => [ 9 '@type' => 'Person',10 'name' => 'John Smith',11 'url' => 'https://john.example.com',12 'image' => 'https://john.example.com/avatar.jpg',13 ],14],
Then, in your markdown:
1---2title: My Awesome Blog Post3author: jane_doe4date: 2024-06-305image: /blog-images/featured.webp6excerpt: This is a summary of my awesome blog post.7---
#Publisher Settings
If you’d like to change your site or company details, update the 'publisher'
array in config/prezet.php
:
1'publisher' => [2 '@type' => 'Organization',3 'name' => 'My Company Name',4 'url' => 'https://mycompany.example.com',5 'logo' => 'https://mycompany.example.com/logo.svg',6 'image' => 'https://mycompany.example.com/ogimage.png',7],
#Overriding the GetLinkedData
Action
For advanced changes—like adding custom properties or adjusting how fields are merged—you can override the GetLinkedData
action:
-
Create Your Action
1// app/Actions/CustomGetLinkedData.php2namespace App\Actions;34use BenBjurstrom\Prezet\Actions\GetLinkedData;5use BenBjurstrom\Prezet\Data\DocumentData;67class CustomGetLinkedData extends GetLinkedData8{9 public function handle(DocumentData $document): array10 {11 $jsonLd = parent::handle($document);1213 // Add your own fields or logic14 $jsonLd['isPartOf'] = [15 '@type' => 'Blog',16 'name' => 'My Custom Blog',17 ];1819 return $jsonLd;20 }21} -
Bind Your Action
1// app/Providers/AppServiceProvider.php2namespace App\Providers;34use Illuminate\Support\ServiceProvider;5use BenBjurstrom\Prezet\Actions\GetLinkedData;6use App\Actions\CustomGetLinkedData;78class AppServiceProvider extends ServiceProvider9{10 public function register(): void11 {12 $this->app->bind(GetLinkedData::class, CustomGetLinkedData::class);13 }14}
Prezet will now resolve your custom version of the action whenever structured data is generated.
#Verifying Your Structured Data
Once your page is live, you can use Google’s Rich Results Test or other structured data testing tools to confirm that your JSON-LD is recognized and valid. Properly formed structured data can improve your site’s appearance in search results and increase user engagement.
Next Steps
- To learn more about customizing other aspects of Prezet, see the Controllers or Actions documentation.
- Explore additional ways to add or modify metadata via the Front Matter guide.
- For more details on how Prezet handles SEO and meta tags, head over to the SEO Features page.