Ghost/core/frontend/meta/get-meta.js
Hannah Wolfe af4bfb8862
Changed meta filenames to correct casing
- purely for cleanliness!
- we use kebabcase by default
- tests should be kebab-case-file_spec.js (one day we want this to be .test.js)
2021-07-01 12:30:25 +01:00

96 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;