mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
closes #8793 - 1.3 post excerpt migration - add 1.3 migration to add `excerpt` to post schema NOTE: - knex-migrator relies on the package.json safe version - so right now Ghost is on 1.2 - the migration script is for 1.3 - if you pull down the PR (or if we merge this PR into master), you have to run `knex-migrator migrate --v 1.3 --force` - knex-migrator will tell you what you have todo - Bump dependencies - knex-migrator@2.1.3 - Soft limit for custom_excerpt - Extended {{excerpt}} to use custom excerpt - when a `custom_excerpt` field exists, the `{{excerpt}}` helper will output this and fall back to autogenerated excerpt if not. - Refactored behaviour of (meta) description - html tag `<meta name="description" />` for posts, tags and author doesn't get rendered if not provided. - fallback for `author.bio` removed - fallback for `tag.description` removed - structured data and schema.org for `post` context takes the following order to render description fields: 1. custom excerpt 2. meta description 3. automated excerpt (50 words) - updated and added tests to reflect the changes
54 lines
2.3 KiB
JavaScript
54 lines
2.3 KiB
JavaScript
var socialUrls = require('../../utils/social-urls');
|
|
|
|
function getStructuredData(metaData) {
|
|
var structuredData,
|
|
card = 'summary';
|
|
|
|
if (metaData.coverImage.url) {
|
|
card = 'summary_large_image';
|
|
}
|
|
|
|
structuredData = {
|
|
'og:site_name': metaData.blog.title,
|
|
'og:type': metaData.ogType,
|
|
'og:title': metaData.metaTitle,
|
|
// CASE: metaData.excerpt for post context is populated by either the custom excerpt,
|
|
// the meta description, or the automated excerpt of 50 words. It is empty for any
|
|
// other context and *always* uses the provided meta description fields.
|
|
'og:description': metaData.excerpt || metaData.metaDescription,
|
|
'og:url': metaData.canonicalUrl,
|
|
'og:image': metaData.coverImage.url,
|
|
'article:published_time': metaData.publishedDate,
|
|
'article:modified_time': metaData.modifiedDate,
|
|
'article:tag': metaData.keywords,
|
|
'article:publisher': metaData.blog.facebook ? socialUrls.facebookUrl(metaData.blog.facebook) : undefined,
|
|
'article:author': metaData.authorFacebook ? socialUrls.facebookUrl(metaData.authorFacebook) : undefined,
|
|
'twitter:card': card,
|
|
'twitter:title': metaData.metaTitle,
|
|
'twitter:description': metaData.excerpt || metaData.metaDescription,
|
|
'twitter:url': metaData.canonicalUrl,
|
|
'twitter:image': metaData.coverImage.url,
|
|
'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': metaData.creatorTwitter || undefined
|
|
};
|
|
|
|
if (metaData.coverImage.dimensions) {
|
|
structuredData['og:image:width'] = metaData.coverImage.dimensions.width;
|
|
structuredData['og:image:height'] = metaData.coverImage.dimensions.height;
|
|
}
|
|
|
|
// 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;
|