Ghost/core/server/data/meta/structured_data.js
JT Turner 1f4c01d207 Started moving meta data fetching to functions.
issue #6186
- Moved asset helper logic to a asset url function.
- Created author image function to be used in ghost_head helper.
- Created author url function to be used in the ghost_head helper.
- Created canonical url function to be used in the ghost_head helper.
- Moved meta_description helper logic to a function.
- Moved excerpt helper logic to a function.
- Created an index in data/meta to be used in ghost_head helper to get all data.
- Created keyword function to be used in the ghost_head helper.
- Created modified data function to be used in the ghost_head helper.
- Created next url function to be used in the ghost_head helper.
- Created ogType function to be used in the ghost_head helper.
- Created previous url function to be used in the ghost_head helper.
- Created published data function to be used in the ghost_head helper.
- Created rss url function to be used in the ghost_head helper.
- Created schema function to be used in the ghost_head helper.
- Created structured data function to be used in the ghost_head helper.
- Moved meta_title helper logic to a title function.
- Moved url helper logic to a url function.
- Wrote tests for all the new functions

This is just the first step. I plan on refactoring the ghost head to use these new functions.
2016-01-23 13:58:21 -08:00

37 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,
'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,
'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;