mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
1785611db9
- The main aim here is to end up with a simple and clear public API for the meta module - Secondarily, we want to make it a bit clearer which bits don't really belong here so we can see what to do with them - To achieve this, the main logic has been moved into get-meta (although there's still some logic here which needs moving further) - The index.js now has a small clear public API, and the proxy, which is the only way this is consumed, is able to use the public API directly
95 lines
3.7 KiB
JavaScript
95 lines
3.7 KiB
JavaScript
const Promise = require('bluebird');
|
|
const settingsCache = require('../../shared/settings-cache');
|
|
const urlUtils = require('../../shared/url-utils');
|
|
const logging = require('@tryghost/logging');
|
|
|
|
// These are in filename order
|
|
const getAmpUrl = require('./amp_url');
|
|
const getAuthorFacebook = require('./author_fb_url');
|
|
const getAuthorImage = require('./author_image');
|
|
const getAuthorUrl = require('./author_url');
|
|
const getBlogLogo = require('./blog_logo');
|
|
const getCanonicalUrl = require('./canonical_url');
|
|
const getCoverImage = require('./cover_image');
|
|
const getCreatorTwitter = require('./creator_url');
|
|
const getDescription = require('./description');
|
|
const getExcerpt = require('./excerpt');
|
|
const getImageDimensions = require('./image-dimensions');
|
|
const getKeywords = require('./keywords');
|
|
const getModifiedDate = require('./modified_date');
|
|
const getOgType = require('./og_type');
|
|
const getOgImage = require('./og_image');
|
|
const getPaginatedUrl = require('./paginated_url');
|
|
const getPublishedDate = require('./published_date');
|
|
const getRssUrl = require('./rss_url');
|
|
const getSchema = require('./schema');
|
|
const getStructuredData = require('./structured_data');
|
|
const getTitle = require('./title');
|
|
const getTwitterImage = require('./twitter_image');
|
|
const getUrl = require('./url');
|
|
|
|
function getMetaData(data, root) {
|
|
const 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,
|
|
excerpt: getExcerpt(data),
|
|
coverImage: {
|
|
url: getCoverImage(data)
|
|
},
|
|
authorImage: {
|
|
url: getAuthorImage(data, true)
|
|
},
|
|
ogImage: {
|
|
url: getOgImage(data)
|
|
},
|
|
ogTitle: getTitle(data, root, {property: 'og'}),
|
|
ogDescription: getDescription(data, root, {property: 'og'}),
|
|
twitterImage: getTwitterImage(data),
|
|
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('timezone'),
|
|
navigation: settingsCache.get('navigation'),
|
|
icon: settingsCache.get('icon'),
|
|
cover_image: settingsCache.get('cover_image'),
|
|
logo: getBlogLogo(),
|
|
amp: settingsCache.get('amp')
|
|
}
|
|
};
|
|
|
|
if (data.post && data.post.primary_author && data.post.primary_author.name) {
|
|
metaData.authorName = data.post.primary_author.name;
|
|
}
|
|
|
|
// @TODO: wrap this in a utility function
|
|
return Promise.props(getImageDimensions(metaData)).then(function () {
|
|
metaData.structuredData = getStructuredData(metaData);
|
|
metaData.schema = getSchema(metaData, data);
|
|
|
|
return metaData;
|
|
}).catch(function (err) {
|
|
logging.error(err);
|
|
return metaData;
|
|
});
|
|
}
|
|
|
|
module.exports = getMetaData;
|