mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
d7b9eb6176
refs #6534 - this is an initial fix for having no description at all unless a meta description is provided - we may need to tweak the lengths / provide different lengths for different values in future
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
function getStructuredData(metaData) {
|
|
var structuredData,
|
|
card = 'summary';
|
|
|
|
if (metaData.coverImage) {
|
|
card = 'summary_large_image';
|
|
}
|
|
|
|
structuredData = {
|
|
'og:site_name': metaData.blog.title,
|
|
'og:type': metaData.ogType,
|
|
'og:title': metaData.metaTitle,
|
|
'og:description': metaData.metaDescription || metaData.excerpt,
|
|
'og:url': metaData.canonicalUrl,
|
|
'og:image': metaData.coverImage,
|
|
'article:published_time': metaData.publishedDate,
|
|
'article:modified_time': metaData.modifiedDate,
|
|
'article:tag': metaData.keywords,
|
|
'twitter:card': card,
|
|
'twitter:title': metaData.metaTitle,
|
|
'twitter:description': metaData.metaDescription || metaData.excerpt,
|
|
'twitter:url': metaData.canonicalUrl,
|
|
'twitter:image:src': metaData.coverImage
|
|
};
|
|
|
|
// return structored data removing null or undefined keys
|
|
return Object.keys(structuredData).reduce(function (data, key) {
|
|
var content = structuredData[key];
|
|
if (content !== null && typeof content !== 'undefined') {
|
|
data[key] = content;
|
|
}
|
|
return data;
|
|
}, {});
|
|
}
|
|
|
|
module.exports = getStructuredData;
|