2016-01-17 05:07:52 -05:00
|
|
|
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,
|
2016-02-18 06:47:08 -05:00
|
|
|
'og:description': metaData.metaDescription || metaData.excerpt,
|
2016-01-17 05:07:52 -05:00
|
|
|
'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,
|
2016-02-18 06:47:08 -05:00
|
|
|
'twitter:description': metaData.metaDescription || metaData.excerpt,
|
2016-01-17 05:07:52 -05:00
|
|
|
'twitter:url': metaData.canonicalUrl,
|
2016-02-20 10:55:35 -05:00
|
|
|
'twitter:image:src': metaData.coverImage,
|
|
|
|
'twitter:label1': metaData.authorName ? 'Written by' : undefined,
|
|
|
|
'twitter:data1': metaData.authorName,
|
|
|
|
'twitter:label2': metaData.keywords ? 'Filed under' : undefined,
|
|
|
|
'twitter:data2': metaData.keywords ? metaData.keywords.join(', ') : undefined
|
2016-01-17 05:07:52 -05:00
|
|
|
};
|
|
|
|
|
2016-02-20 10:55:35 -05:00
|
|
|
// return structured data removing null or undefined keys
|
2016-01-17 05:07:52 -05:00
|
|
|
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;
|