mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
b7bd6d9968
closes #6534 - new input fields in general settings incl. validation - facebook and twitter as new models in settings.js - adds values for facebook and twitter to default-settings.js - adds blog helpers for facebook and twittter - rather than saving the whole URL, the Twitter username incl. '@' will be extracted from URL and saved in the settings. The User will still input the full URL. After saving the blog setting, the stored Twitter username will be parsed again as the full URL and available in the input field. A custom transform is used for this. - adding meta fields to be rendered in {{ghost_head}}: - '<meta property="article:publisher" content="https://www.facebook.com/page" />' and - '<meta name="twitter:site" content="@user"/>' - adds facebook and twitter to unit test for structured data - adds unit test for general settings - adds acceptance test for new input fields in general settings - adds a custom transform for twitter model to save only the username to the server - adds unit test for transform
50 lines
1.9 KiB
JavaScript
50 lines
1.9 KiB
JavaScript
function getStructuredData(metaData) {
|
|
var structuredData,
|
|
card = 'summary',
|
|
twitterUser;
|
|
|
|
if (metaData.coverImage) {
|
|
card = 'summary_large_image';
|
|
}
|
|
|
|
if (metaData.creatorTwitter) {
|
|
twitterUser = '@' + metaData.creatorTwitter.match(/(?:https:\/\/)(?:twitter\.com)\/(?:#!\/)?@?([^\/]*)/)[1];
|
|
}
|
|
|
|
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,
|
|
'article:publisher': metaData.blog.facebook || undefined,
|
|
'article:author': metaData.authorFacebook || undefined,
|
|
'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,
|
|
'twitter:site': metaData.blog.twitter || undefined,
|
|
'twitter:creator': twitterUser || 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;
|