brotkrueml / schema

TYPO3 extension providing an API and view helpers for schema.org markup
https://extensions.typo3.org/extension/schema
GNU General Public License v2.0
32 stars 9 forks source link

Only generate breadcrumb automatically in case there is none, yet #104

Closed ohader closed 1 year ago

ohader commented 1 year ago

Current behavior

When having extension configuration automaticBreadcrumbSchemaGeneration enabled, and a breadcrumb has already been provided via Fluid <schema:type.BreadcrumbList>...</schema:type.BreadcrumbList>, AddBreadcrumbList would override the breadcrumb again.

Expected behavior/output

AddBreadcrumbList should only inject a breadcrumb in case there's non yet.

Steps to reproduce

Environment

brotkrueml commented 1 year ago

@ohader Thanks for the issue. I can't reproduce the overriding, however, the breadcrumb from the template is added, so you now have the automatically generated breadcrumb and the one from the template, for example:

{
  "@context":"https://schema.org/",
  "@graph":[{
    "@type":"WebPage",
    "breadcrumb":[{
      "@type":"BreadcrumbList",
      "itemListElement": {
        "@type":"ListItem",
        "item":"/",
        "name":"Test",
        "position":"1"
      }
    }, {
      "@type":"BreadcrumbList",
      "itemListElement":{
        "@type":"ListItem",
        "item":{
          "@type":"WebPage",
          "@id":"/blog"
        }
      }
    }]
  }]
}

I would define this as correct behaviour, as multiple breadcrumbs are possible: https://developers.google.com/search/docs/appearance/structured-data/breadcrumb?hl=en#html_example

What do you think?

ohader commented 1 year ago

Sorry, I got the original description wrong. Indeed it was NOT overridden, but I got two conflicting BreadCrumbLists. In my scenario the auto-generation is fine for regular pages, but for plugins rendering additional aspects, I was aiming for a possibility to avoid auto-generation and use a custom breadcrumb generation.

Example: https://indiemusik-festival.de/events/festival-2023/act/aetna (uses the patch of PR #105 already)

brotkrueml commented 1 year ago

As multiple breadcrumbs are possible, the given PR may be breaking for a user who relies on them. I was aware of multiple breadcrumbs when implementing them, so it is a feature.

I can think of a new extension configuration "Allow only one breadcrumb list". If this is set, the last added one wins. The problem is not bound only to the automatic embedding of the breadcrumb, but also when one adds the breadcrumb via the Fluid layout and wants to override it in a specific extension template.

This way, the SchemaManager does the work: If the setting is activated, just override everytime the breadcrumbLists property. Otherwise, add it to the list. There are some edge cases to consider, for example, it is possible to set a webpage type with one or more breadcrumbs.

This would solve your issue, I think?

ohader commented 1 year ago

I'll give it a try with multiple breadcrumbs... let's see how Google handles them finally in their index. The preview looks okay https://search.google.com/test/rich-results/result?id=NY0TXQnHASXR3DE0RCciUA

ohader commented 1 year ago

Closing this issue, probably will reopen at a later time again...

brotkrueml commented 1 year ago

@ohader I added a new configuration setting "Allow only one breadcrumb list" to the extension settings. - currently in branch 2.7.x-dev (main).