Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make final breadcrumb's item field optional #1477

Open
micahsteinberg opened this issue Jul 5, 2024 · 0 comments
Open

Make final breadcrumb's item field optional #1477

micahsteinberg opened this issue Jul 5, 2024 · 0 comments

Comments

@micahsteinberg
Copy link

micahsteinberg commented Jul 5, 2024

The Google SEO doc for adding breadcrumbs says

If the breadcrumb is the last item in the breadcrumb trail, item is not required. If item isn't included for the last item, Google uses the URL of the containing page.

Currently, providing an item for every breadcrumb is required in this library. This makes adding the final breadcrumb more difficult since you have to manually add the current url. I wish BreadCrumbJsonLdProps => ItemListElements => item would be optional. That way it would more closely follow Google's recommendation, and the final url would be added for you automatically.

An example output would be:

{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [{
    "@type": "ListItem",
    "position": 1,
    "name": "Books",
    "item": "https://example.com/books"
  },{
    "@type": "ListItem",
    "position": 2,
    "name": "Science Fiction",
    "item": "https://example.com/books/sciencefiction"
  },{
    "@type": "ListItem",
    "position": 3,
    "name": "Award Winners"
  }]
}

Related to #95

The new prop types could look like:

export interface BreadCrumbJsonLdProps extends JsonLdProps {
  itemListElements: {
    item?: string;
    name: string;
    position: number;
  }[];
}

or maybe something like this instead to capture that it should only be for the last one:

export interface BreadCrumbJsonLdProps extends JsonLdProps {
  itemListElements: {
    item: string;
    name: string;
    position: number;
    isFinalBreadcrumb?: boolean;
  } | {
    item?: string;
    name: string;
    position: number;
    isFinalBreadcrumb: true;
  }[];
}

I realize this isn't entirely trivial to add because of how setItemListElements is used, but would be a nice addition! Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant