2016-01-17 13:07:52 +03:00
|
|
|
function getStructuredData(metaData) {
|
|
|
|
var structuredData,
|
2016-03-03 11:52:27 +03:00
|
|
|
card = 'summary',
|
|
|
|
twitterUser;
|
2016-01-17 13:07:52 +03:00
|
|
|
|
|
|
|
if (metaData.coverImage) {
|
|
|
|
card = 'summary_large_image';
|
|
|
|
}
|
|
|
|
|
2016-03-03 11:52:27 +03:00
|
|
|
if (metaData.creatorTwitter) {
|
|
|
|
twitterUser = '@' + metaData.creatorTwitter.match(/(?:https:\/\/)(?:twitter\.com)\/(?:#!\/)?@?([^\/]*)/)[1];
|
|
|
|
}
|
|
|
|
|
2016-01-17 13:07:52 +03:00
|
|
|
structuredData = {
|
|
|
|
'og:site_name': metaData.blog.title,
|
|
|
|
'og:type': metaData.ogType,
|
|
|
|
'og:title': metaData.metaTitle,
|
2016-02-18 14:47:08 +03:00
|
|
|
'og:description': metaData.metaDescription || metaData.excerpt,
|
2016-01-17 13:07:52 +03:00
|
|
|
'og:url': metaData.canonicalUrl,
|
|
|
|
'og:image': metaData.coverImage,
|
|
|
|
'article:published_time': metaData.publishedDate,
|
|
|
|
'article:modified_time': metaData.modifiedDate,
|
|
|
|
'article:tag': metaData.keywords,
|
2016-03-03 11:52:27 +03:00
|
|
|
'article:publisher': metaData.blog.facebook || undefined,
|
|
|
|
'article:author': metaData.authorFacebook || undefined,
|
2016-01-17 13:07:52 +03:00
|
|
|
'twitter:card': card,
|
|
|
|
'twitter:title': metaData.metaTitle,
|
2016-02-18 14:47:08 +03:00
|
|
|
'twitter:description': metaData.metaDescription || metaData.excerpt,
|
2016-01-17 13:07:52 +03:00
|
|
|
'twitter:url': metaData.canonicalUrl,
|
2016-02-20 18:55:35 +03:00
|
|
|
'twitter:image:src': metaData.coverImage,
|
|
|
|
'twitter:label1': metaData.authorName ? 'Written by' : undefined,
|
|
|
|
'twitter:data1': metaData.authorName,
|
|
|
|
'twitter:label2': metaData.keywords ? 'Filed under' : undefined,
|
2016-03-03 11:52:27 +03:00
|
|
|
'twitter:data2': metaData.keywords ? metaData.keywords.join(', ') : undefined,
|
|
|
|
'twitter:site': metaData.blog.twitter || undefined,
|
|
|
|
'twitter:creator': twitterUser || undefined
|
2016-01-17 13:07:52 +03:00
|
|
|
};
|
|
|
|
|
2016-02-20 18:55:35 +03:00
|
|
|
// return structured data removing null or undefined keys
|
2016-01-17 13:07:52 +03: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;
|