0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/core/server/data/meta/structured_data.js
Hannah Wolfe dcc8bcc4f1 Strutured data: Slack Unfurls & published_at fix
refs #6534

- fixes a bug where published_at was incorrectly falling back to the created_at date
- updated meta index to get author name
- add written by & filed under labels + data if the values are present (only on posts/pages)
- updated tests
2016-02-22 01:45:00 +01:00

40 lines
1.5 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,
'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
};
// return structured 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;