Skip to content

Commit

Permalink
return null breadcrumb ld when there are no items
Browse files Browse the repository at this point in the history
  • Loading branch information
juanSanchezAlcala committed May 23, 2022
1 parent 66b04f7 commit b02cf6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions test/types/breadcrumb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ describe('Type: Breadcrumb', function () {
auxArticle.displayConcept = null;
delete auxArticle.displayConcept;
const result = breadcrumb(auxArticle);
expect(result).to.contain({ '@context': 'https://schema.org', '@type': 'BreadcrumbList' });
expect(result.itemListElement.length).to.equals(0);
expect(result).to.equal(null);
});
});
6 changes: 5 additions & 1 deletion types/breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ function getBreadcrumbItem (index,name,url){
}

module.exports = (content) => {
const items = getBreadcrumbItems(content);
if(!items || items.length <= 0)
return null;

const baseSchema = {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
'itemListElement' : getBreadcrumbItems(content)
'itemListElement' : items
};

return baseSchema;
Expand Down

0 comments on commit b02cf6d

Please sign in to comment.