ralphjsmit/laravel-seo

"Article Schema Validation": Error for field "dateUpdated" - Should be "dateModified" instead.

camya opened this issue · 2 comments

camya commented

I added an "Article Schema" to my SEOData object.

Problem: The $article->dateModified property is rendered as invalid schema field dateUpdated in src/Schema/ArticleSchema.php. The field in the schema should be named dateModified too.

This creates an invalid schema. https://validator.schema.org/ (Article Schema specification: https://schema.org/Article)

Error message of the Schema Validator: "dateUpdated" - The property dateUpdated is not recognized by the schema (e.g. schema.org) for an object of type Article.

1. Set the SEOData object with "dateModified"...

$seoData = new SEOData(
    title: $post->title,
    ...
    schema: SchemaCollection::initialize()->addArticle(
        function (ArticleSchema $article) use ($post) {
            $article->datePublished = $post->published_at;
            $article->dateModified = $post->updated_at;
            $article->addAuthor('Team');
            return $article;
        }
    ),
);

2. Output is created with wrong "dateUpdated" key.

See src/Schema/ArticleSchema.php: Line 88 should be updated to 'dateModified' => $this->dateModified->toIso8601String()

public function generateInner(): string
{
    return collect([
        '@context' => 'https://schema.org',
        '@type' => $this->type,
        'mainEntityOfPage' => [
            '@type' => 'WebPage',
            '@id' => $this->url,
        ],
        'datePublished' => $this->datePublished->toIso8601String(),
        'dateUpdated' => $this->dateModified->toIso8601String(),
        'headline' => $this->headline,
    ])
        ->when($this->authors, fn (Collection $collection): Collection => $collection->put('author', $this->authors))
        ->when($this->description, fn (Collection $collection): Collection => $collection->put('description', $this->description))
        ->when($this->image, fn (Collection $collection): Collection => $collection->put('image', $this->image))
        ->when($this->articleBody, fn (Collection $collection): Collection => $collection->put('articleBody', $this->articleBody))
        ->pipeThrough($this->markupTransformers)
        ->toJson();
}

Thanks for reporting Andreas, has been fixed in 1.2.1!

camya commented

Looks fine. Just tested it. Thank you for the update.