mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Refactored meta index
- 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
This commit is contained in:
parent
9fbc0b7f2b
commit
1785611db9
3 changed files with 106 additions and 101 deletions
95
core/frontend/meta/get-meta.js
Normal file
95
core/frontend/meta/get-meta.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
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;
|
|
@ -1,92 +1,10 @@
|
|||
const Promise = require('bluebird');
|
||||
const settingsCache = require('../../shared/settings-cache');
|
||||
const urlUtils = require('../../shared/url-utils');
|
||||
const logging = require('@tryghost/logging');
|
||||
const getUrl = require('./url');
|
||||
const getImageDimensions = require('./image-dimensions');
|
||||
const getCanonicalUrl = require('./canonical_url');
|
||||
const getAmpUrl = require('./amp_url');
|
||||
const getPaginatedUrl = require('./paginated_url');
|
||||
const getAuthorUrl = require('./author_url');
|
||||
const getBlogLogo = require('./blog_logo');
|
||||
const getRssUrl = require('./rss_url');
|
||||
const getTitle = require('./title');
|
||||
const getDescription = require('./description');
|
||||
const getCoverImage = require('./cover_image');
|
||||
const getAuthorImage = require('./author_image');
|
||||
const getAuthorFacebook = require('./author_fb_url');
|
||||
const getCreatorTwitter = require('./creator_url');
|
||||
const getKeywords = require('./keywords');
|
||||
const getPublishedDate = require('./published_date');
|
||||
const getModifiedDate = require('./modified_date');
|
||||
const getOgType = require('./og_type');
|
||||
const getOgImage = require('./og_image');
|
||||
const getTwitterImage = require('./twitter_image');
|
||||
const getStructuredData = require('./structured_data');
|
||||
const getSchema = require('./schema');
|
||||
const getExcerpt = require('./excerpt');
|
||||
|
||||
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, true)
|
||||
},
|
||||
authorImage: {
|
||||
url: getAuthorImage(data, true)
|
||||
},
|
||||
ogImage: {
|
||||
url: getOgImage(data)
|
||||
},
|
||||
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('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;
|
||||
}
|
||||
|
||||
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;
|
||||
// Public API (only used in proxy.js)
|
||||
module.exports = {
|
||||
get: require('./get-meta'), // ghost_head
|
||||
getAssetUrl: require('./asset_url'), // asset
|
||||
getMetaDataExcerpt: require('./generate-excerpt'), // excerpt
|
||||
getMetaDataDescription: require('./description'), // meta_desc
|
||||
getMetaDataTitle: require('./title'), // meta_title
|
||||
getPaginatedUrl: require('./paginated_url'), // page_url
|
||||
getMetaDataUrl: require('./url') // url
|
||||
};
|
||||
|
|
|
@ -50,15 +50,7 @@ module.exports = {
|
|||
labs: require('../../server/services/labs'),
|
||||
|
||||
// Things required from data/meta
|
||||
metaData: {
|
||||
get: require('../meta'), // ghost_head
|
||||
getAssetUrl: require('../meta/asset_url'), // asset
|
||||
getMetaDataExcerpt: require('../meta/generate-excerpt'), // excerpt
|
||||
getMetaDataDescription: require('../meta/description'), // meta_desc
|
||||
getMetaDataTitle: require('../meta/title'), // meta_title
|
||||
getPaginatedUrl: require('../meta/paginated_url'), // page_url
|
||||
getMetaDataUrl: require('../meta/url') // url
|
||||
},
|
||||
metaData: require('../meta'),
|
||||
|
||||
// The local template thing, should this be merged with the channels one?
|
||||
templates: require('./theme-engine/handlebars/template'),
|
||||
|
|
Loading…
Add table
Reference in a new issue