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

  1. Front Matter: Prezet extracts key information—like title, date, excerpt, image, and author—from your front matter.
  2. Linked Data Action: This data is then passed through the GetLinkedData action, which compiles your post’s structured data in a JSON-LD format.
  3. Blade Template: The JSON-LD is injected into the <head> section in resources/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 the title in front matter.
  • Publication Date (datePublished): Derived from the front matter date 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 in config/prezet.php.
  • Publisher (publisher): Defined in the 'publisher' array of config/prezet.php.
  • Image (image): Uses the front matter image field if set; otherwise defaults to your publisher's image.

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 Post
3author: jane_doe
4date: 2024-06-30
5image: /blog-images/featured.webp
6excerpt: 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:

  1. Create Your Action

    1// app/Actions/CustomGetLinkedData.php
    2namespace App\Actions;
    3 
    4use BenBjurstrom\Prezet\Actions\GetLinkedData;
    5use BenBjurstrom\Prezet\Data\DocumentData;
    6 
    7class CustomGetLinkedData extends GetLinkedData
    8{
    9 public function handle(DocumentData $document): array
    10 {
    11 $jsonLd = parent::handle($document);
    12 
    13 // Add your own fields or logic
    14 $jsonLd['isPartOf'] = [
    15 '@type' => 'Blog',
    16 'name' => 'My Custom Blog',
    17 ];
    18 
    19 return $jsonLd;
    20 }
    21}
  2. Bind Your Action

    1// app/Providers/AppServiceProvider.php
    2namespace App\Providers;
    3 
    4use Illuminate\Support\ServiceProvider;
    5use BenBjurstrom\Prezet\Actions\GetLinkedData;
    6use App\Actions\CustomGetLinkedData;
    7 
    8class AppServiceProvider extends ServiceProvider
    9{
    10 public function register(): void
    11 {
    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.