Skip to content

Instantly share code, notes, and snippets.

@JakeLabate
Last active June 4, 2023 15:05
Show Gist options
  • Save JakeLabate/05ea94bfcfbcd68b3e052893195346d7 to your computer and use it in GitHub Desktop.
Save JakeLabate/05ea94bfcfbcd68b3e052893195346d7 to your computer and use it in GitHub Desktop.
function Brand({url, name, legalName, description, telephone, email, logoUrl, address, sameAs}) {
return {
'@context': 'https://schema.org', // https://schema.org/Brand
'@type': 'Brand',
'@id': id('Brand', name || legalName),
'url': url,
'name': name,
'alternateName': legalName,
'description': description,
'inLanguage': 'en-US',
'publisher': id('Publisher', name || legalName),
'telephone': telephone,
'email': email,
'logo': ImageObject({
src: logoUrl,
imageName: name + ' logo',
}),
'address': address,
'sameAs': sameAs,
}
}
function BreadcrumbList({breadcrumbArr}) {
// get the name of the last item -> used below
const pathName = breadcrumbArr[breadcrumbArr.length - 1].name;
const breadcrumbList = {
'@context': 'https://schema.org', // https://schema.org/BreadcrumbList
'_requiredKeys': ['name', 'itemListElement'],
'@type': 'BreadcrumbList',
'@id': id('BreadcrumbList', pathName),
'name': pathName,
'itemListElement': [],
};
breadcrumbArr.forEach(function (breadcrumb, index) {
breadcrumbList.itemListElement.push(ListItem({
name: breadcrumb.name,
position: index + 1,
item: breadcrumb.url,
}));
});
return breadcrumbList;
}
function BroadcastEvent({broadcastName, liveVideo, liveStart, liveEnd}) {
return { // to use for Live videos with BroadcastEvent
'@context': 'https://schema.org', // https://schema.org/BroadcastEvent
'_requiredKeys': ['name', 'isLiveBroadcast', 'startDate'],
'@type': 'BroadcastEvent', // https://developers.google.com/search/docs/appearance/structured-data/video#broadcast-event
'@id': id('BroadcastEvent', broadcastName),
'name': broadcastName,
'isLiveBroadcast': type_boolean(liveVideo),
'startDate': formatDateToISO(liveStart), // For these two, might create something like formatDateAndTimeToISO to get a full ISO format for more specific events
'endDate': formatDateToISO(liveEnd),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment