Ghost/core/frontend/meta/index.js
Naz Gargol a9050f68ea
🔥 Removed V1 code/references in frontend helpers/meta layers (#11080)
no issue

- Removed deprecated 'blog' reference from frontend data. The alias (site->blog) stays till next version (v4) as it's not leaving much of technical debt but would ease the migration process for anybody still using it. 
- The follow up to this is substitute of all references to `options.data.blog` with `options.data.site` in "frontend"
- Fixed test utils helper to use `site` instead of `blog`
- Removed 0.1 flag checks in {{get}} helper
- Removed user aliasing from {{get}} helper
- Removed unused translation for {{get}} helper
- Added a note to excerpt changes in metadata for future reference
- Removed page alias used in description helper. The mix of page context with post object in the metadata was only possible in v0.1
- Changed mock in ghost_head helper to use v2
- Removed unneeded test for body class helper
2019-09-10 11:37:04 +02:00

111 lines
4.8 KiB
JavaScript

var Promise = require('bluebird'),
settingsCache = require('../../server/services/settings/cache'),
urlUtils = require('../../server/lib/url-utils'),
common = require('../../server/lib/common'),
getUrl = require('./url'),
getImageDimensions = require('./image-dimensions'),
getCanonicalUrl = require('./canonical_url'),
getAmpUrl = require('./amp_url'),
getPaginatedUrl = require('./paginated_url'),
getAuthorUrl = require('./author_url'),
getBlogLogo = require('./blog_logo'),
getRssUrl = require('./rss_url'),
getTitle = require('./title'),
getDescription = require('./description'),
getCoverImage = require('./cover_image'),
getAuthorImage = require('./author_image'),
getAuthorFacebook = require('./author_fb_url'),
getCreatorTwitter = require('./creator_url'),
getKeywords = require('./keywords'),
getPublishedDate = require('./published_date'),
getModifiedDate = require('./modified_date'),
getOgType = require('./og_type'),
getOgImage = require('./og_image'),
getTwitterImage = require('./twitter_image'),
getStructuredData = require('./structured_data'),
getSchema = require('./schema'),
getExcerpt = require('./excerpt');
function getMetaData(data, root) {
var metaData = {
url: getUrl(data, true),
canonicalUrl: getCanonicalUrl(data),
ampUrl: getAmpUrl(data),
previousUrl: getPaginatedUrl('prev', data, true),
nextUrl: getPaginatedUrl('next', data, true),
authorUrl: getAuthorUrl(data, true),
rssUrl: getRssUrl(data, true),
metaTitle: getTitle(data, root),
metaDescription: getDescription(data, root) || null,
coverImage: {
url: getCoverImage(data, true)
},
authorImage: {
url: getAuthorImage(data, true)
},
ogImage: {
url: getOgImage(data, true)
},
ogTitle: getTitle(data, root, {property: 'og'}),
ogDescription: getDescription(data, root, {property: 'og'}),
twitterImage: getTwitterImage(data, true),
twitterTitle: getTitle(data, root, {property: 'twitter'}),
twitterDescription: getDescription(data, root, {property: 'twitter'}),
authorFacebook: getAuthorFacebook(data),
creatorTwitter: getCreatorTwitter(data),
keywords: getKeywords(data),
publishedDate: getPublishedDate(data),
modifiedDate: getModifiedDate(data),
ogType: getOgType(data),
// @TODO: pass into each meta helper - wrap each helper
site: {
title: settingsCache.get('title'),
description: settingsCache.get('description'),
url: urlUtils.urlFor('home', true),
facebook: settingsCache.get('facebook'),
twitter: settingsCache.get('twitter'),
timezone: settingsCache.get('active_timezone'),
navigation: settingsCache.get('navigation'),
icon: settingsCache.get('icon'),
cover_image: settingsCache.get('cover_image'),
logo: getBlogLogo(),
amp: settingsCache.get('amp')
}
},
customExcerpt,
metaDescription,
fallbackExcerpt;
// TODO: cleanup these if statements
if (data.post || data.page) {
// There's a specific order for description fields (not <meta name="description" /> !!) in structured data
// and schema.org which is used the description fields (see https://github.com/TryGhost/Ghost/issues/8793):
// 1. CASE: custom_excerpt is populated via the UI
// 2. CASE: no custom_excerpt, but meta_description is poplated via the UI
// 3. CASE: fall back to automated excerpt of 50 words if neither custom_excerpt nor meta_description is provided
// @TODO: https://github.com/TryGhost/Ghost/issues/10062
const prop = data.post ? 'post' : 'page';
customExcerpt = data[prop].excerpt || data[prop].custom_excerpt;
metaDescription = data[prop].meta_description;
fallbackExcerpt = data[prop].html ? getExcerpt(data[prop].html, {words: 50}) : '';
metaData.excerpt = customExcerpt ? customExcerpt : metaDescription ? metaDescription : fallbackExcerpt;
}
if (data.post && data.post.primary_author && data.post.primary_author.name) {
metaData.authorName = data.post.primary_author.name;
}
return Promise.props(getImageDimensions(metaData)).then(function () {
metaData.structuredData = getStructuredData(metaData);
metaData.schema = getSchema(metaData, data);
return metaData;
}).catch(function (err) {
common.logging.error(err);
return metaData;
});
}
module.exports = getMetaData;