Ghost/core/frontend/services/proxy.js
Hannah Wolfe 52b924638d
Removed core @tryghost pkg usage from f/e proxy
- The frontend proxy is meant to be a way to pass critical internal pieces of Ghost core into the frontend
- These fundamental @tryghost packages are shared and can be required directly, hence there's no need to pass them via the proxy
- Reducing the surface area of the proxy reduces the proxies API
- This makes it easier to see what's left in terms of decoupling the frontend, and what will always need to be passed (e.g. api)

Note on @tryghost/social-urls:
- this is a small utility that helps create URLs for social profiles, it's a util for working with data on the frontend aka part of the sdk
- I think there should be many of these small helpers and we'll probably want to bundle them for the frontend at some point
- for now, I'm leaving these as part of the proxy, as need to figure out where they belong
2021-09-28 12:19:02 +01:00

66 lines
2.2 KiB
JavaScript

// This file defines everything that helpers "require"
// With the exception of modules like lodash, Bluebird
// We can later refactor to enforce this something like we did in apps
const hbs = require('./theme-engine/engine');
const settingsCache = require('../../shared/settings-cache');
const config = require('../../shared/config');
// Direct requires:
// - lodash
// - bluebird
// - downsize
// - moment-timezone
// - jsonpath
module.exports = {
hbs: hbs,
SafeString: hbs.SafeString,
escapeExpression: hbs.escapeExpression,
// TODO: Expose less of the API to make this safe
api: require('../../server/api'),
// TODO: Only expose "get"
settingsCache: settingsCache,
// Theme i18n is separate to common i18n
themeI18n: require('./theme-engine/i18n'),
// This is used to detect if "isPost" is true in prevNext.
checks: require('../../server/data/schema').checks,
// Config!
// Keys used:
// isPrivacyDisabled & referrerPolicy used in ghost_head
config: {
get: config.get.bind(config),
isPrivacyDisabled: config.isPrivacyDisabled.bind(config)
},
// Labs utils for enabling/disabling helpers
labs: require('../../shared/labs'),
// Things required from data/meta
metaData: require('../meta'),
// The local template thing, should this be merged with the channels one?
templates: require('./theme-engine/handlebars/template'),
// Various utils, needs cleaning up / simplifying
socialUrls: require('@tryghost/social-urls'),
blogIcon: require('../../server/lib/image').blogIcon,
urlService: require('./url'),
urlUtils: require('../../shared/url-utils'),
localUtils: require('./theme-engine/handlebars/utils'),
// Used by router service and {{get}} helper to prepare data for optimal usage in themes
prepareContextResource(data) {
(Array.isArray(data) ? data : [data]).forEach((resource) => {
// feature_image_caption contains HTML, making it a SafeString spares theme devs from triple-curlies
if (resource.feature_image_caption) {
resource.feature_image_caption = new hbs.SafeString(resource.feature_image_caption);
}
});
}
};