Skip to content

Commit

Permalink
Add v4.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoslavGatev committed Oct 1, 2021
1 parent d578b5e commit 1571e4e
Show file tree
Hide file tree
Showing 105 changed files with 2,786 additions and 2,294 deletions.
14 changes: 7 additions & 7 deletions core/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ async function initCore({ghostServer, config}) {
async function initFrontend() {
debug('Begin: initFrontend');

debug('Begin: Frontend Settings');
const frontendSettings = require('./frontend/services/settings');
await frontendSettings.init();
debug('End: Frontend Settings');
debug('Begin: Frontend Routing Settings');
const routeSettings = require('./server/services/route-settings');
await routeSettings.init();
debug('End: Frontend Routing Settings');

debug('Begin: Themes');
const themeService = require('./server/services/themes');
Expand Down Expand Up @@ -146,16 +146,16 @@ async function initExpressApps() {
async function initDynamicRouting() {
debug('Begin: Dynamic Routing');
const routing = require('./frontend/services/routing');
const frontendSettings = require('./frontend/services/settings');
const routeSettingsService = require('./server/services/route-settings');
const bridge = require('./bridge');

// We pass the frontend API version + the dynamic routes here, so that the frontend services are slightly less tightly-coupled
const apiVersion = bridge.getFrontendApiVersion();
const routeSettings = frontendSettings.get('routes');
const routeSettings = await routeSettingsService.loadRouteSettings();
debug(`Frontend API Version: ${apiVersion}`);

routing.bootstrap.start(apiVersion, routeSettings);
const getRoutesHash = () => frontendSettings.getCurrentHash('routes');
const getRoutesHash = () => routeSettingsService.api.getCurrentHash();

const settings = require('./server/services/settings');
await settings.syncRoutesHash(getRoutesHash);
Expand Down
7 changes: 4 additions & 3 deletions core/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* The bridge is responsible for handing communication from the server to the frontend.
* Data should only be flowing server -> frontend.
* As the architecture improves, the number of cross requires here should go down
* Eventually, the aim is to make this a component that is initialised on boot and is either handed to or actively creates the frontend, if the frontend is desired.
* Eventually, the aim is to make this a component that is initialized on boot and is either handed to or actively creates the frontend, if the frontend is desired.
*
* This file is a great place for all the cross-component event handling in lieu of refactoring
* NOTE: You may require anything from shared, the frontend or server here - it is the one place (other than boot) that is allowed :)
*/

const debug = require('@tryghost/debug')('bridge');
Expand Down Expand Up @@ -40,7 +41,7 @@ class Bridge {
return themeEngine.getActive();
}

activateTheme(loadedTheme, checkedTheme, error) {
activateTheme(loadedTheme, checkedTheme) {
let settings = {
locale: settingsCache.get('lang')
};
Expand All @@ -53,7 +54,7 @@ class Bridge {
previousGhostAPI = this.getActiveTheme().engine('ghost-api');
}

themeEngine.setActive(settings, loadedTheme, checkedTheme, error);
themeEngine.setActive(settings, loadedTheme, checkedTheme);
const currentGhostAPI = this.getActiveTheme().engine('ghost-api');

if (previousGhostAPI !== undefined && (previousGhostAPI !== currentGhostAPI)) {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/frontend/apps/amp/lib/helpers/amp_analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Usage: `{{amp_analytics}}`
//
// Outputs inline scripts used for analytics

const {SafeString, settingsCache} = require('../../../../services/proxy');
const {settingsCache} = require('../../../../services/proxy');
const {SafeString} = require('../../../../services/rendering');

function ampComponents() {
let components = [];
Expand Down
3 changes: 2 additions & 1 deletion core/frontend/apps/amp/lib/helpers/amp_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// By default supported AMP HTML tags (no additional script tag necessary):
// amp-img, amp-ad, amp-embed, amp-video and amp-pixel.
// (less) dirty requires
const {SafeString, settingsCache} = require('../../../../services/proxy');
const {settingsCache} = require('../../../../services/proxy');
const {SafeString} = require('../../../../services/rendering');

function ampComponents() {
let components = [];
Expand Down
6 changes: 5 additions & 1 deletion core/frontend/apps/amp/lib/helpers/amp_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
const Promise = require('bluebird');

const moment = require('moment');
const {SafeString, logging, errors} = require('../../../../services/proxy');
const errors = require('@tryghost/errors');
const logging = require('@tryghost/logging');

const {SafeString} = require('../../../../services/rendering');

const amperizeCache = {};
let allowedAMPTags = [];
let allowedAMPAttributes = {};
Expand Down
2 changes: 1 addition & 1 deletion core/frontend/apps/amp/lib/helpers/amp_style.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {SafeString, escapeExpression} = require('../../../../services/proxy');
const {SafeString, escapeExpression} = require('../../../../services/rendering');

module.exports = function amp_style(options) { // eslint-disable-line camelcase
if (options.data.site.accent_color) {
Expand Down
12 changes: 8 additions & 4 deletions core/frontend/apps/amp/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ const path = require('path');
const express = require('../../../../shared/express');
const ampRouter = express.Router('amp');

// Dirty requires
const {i18n} = require('../../../services/proxy');
const tpl = require('@tryghost/tpl');
const errors = require('@tryghost/errors');

// Dirty requires
const urlService = require('../../../services/url');
const helpers = require('../../../services/routing/helpers');
const templateName = 'amp';

const messages = {
pageNotFound: 'Page not found.'
};

function _renderer(req, res, next) {
res.routerOptions = {
type: 'custom',
Expand All @@ -23,7 +27,7 @@ function _renderer(req, res, next) {

// CASE: we only support amp pages for posts that are not static pages
if (!data.post || data.post.page) {
return next(new errors.NotFoundError({message: i18n.t('errors.errors.pageNotFound')}));
return next(new errors.NotFoundError({message: tpl(messages.pageNotFound)}));
}

// Render Call
Expand Down Expand Up @@ -61,7 +65,7 @@ function getPostData(req, res, next) {

if (!permalinks) {
return next(new errors.NotFoundError({
message: i18n.t('errors.errors.pageNotFound')
message: tpl(messages.pageNotFound)
}));
}

Expand Down
18 changes: 13 additions & 5 deletions core/frontend/apps/private-blogging/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
const {i18n} = require('../../services/proxy');
const urlUtils = require('../../../shared/url-utils');
const tpl = require('@tryghost/tpl');
const logging = require('@tryghost/logging');
const errors = require('@tryghost/errors');
const urlUtils = require('../../../shared/url-utils');
const middleware = require('./lib/middleware');
const router = require('./lib/router');
const registerHelpers = require('./lib/helpers');

const messages = {
urlCannotContainPrivateSubdir: {
error: 'private subdirectory not allowed',
description: 'Your site url in config.js cannot contain a subdirectory called private.',
help: 'Please rename the subdirectory before restarting'
}
};

// routeKeywords.private: 'private'
const PRIVATE_KEYWORD = 'private';

Expand All @@ -17,9 +25,9 @@ let checkSubdir = function checkSubdir() {

if (paths.pop() === PRIVATE_KEYWORD) {
logging.error(new errors.GhostError({
message: i18n.t('errors.config.urlCannotContainPrivateSubdir.error'),
context: i18n.t('errors.config.urlCannotContainPrivateSubdir.description'),
help: i18n.t('errors.config.urlCannotContainPrivateSubdir.help')
message: tpl(messages.urlCannotContainPrivateSubdir.error),
context: tpl(messages.urlCannotContainPrivateSubdir.description),
help: tpl(messages.urlCannotContainPrivateSubdir.help)
}));

// @TODO: why
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Password input used on private.hbs for password-protected blogs

// (less) dirty requires
const {SafeString, templates} = require('../../../../services/proxy');
const {SafeString, templates} = require('../../../../services/rendering');

// We use the name input_password to match the helper for consistency:
module.exports = function input_password(options) { // eslint-disable-line camelcase
Expand Down
11 changes: 8 additions & 3 deletions core/frontend/apps/private-blogging/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ const path = require('path');
const config = require('../../../../shared/config');
const urlUtils = require('../../../../shared/url-utils');
const constants = require('@tryghost/constants');
const {i18n} = require('../../../services/proxy');
const tpl = require('@tryghost/tpl');
const errors = require('@tryghost/errors');
const settingsCache = require('../../../../shared/settings-cache');
// routeKeywords.private: 'private'
const privateRoute = '/private/';

const messages = {
pageNotFound: 'Page not found.',
wrongPassword: 'Wrong password'
};

function verifySessionHash(salt, hash) {
if (!salt || !hash) {
return false;
Expand Down Expand Up @@ -95,7 +100,7 @@ const privateBlogging = {
// CASE: RSS is disabled for private blogging e.g. they create overhead
if (req.path.match(/\/rss\/$/)) {
return next(new errors.NotFoundError({
message: i18n.t('errors.errors.pageNotFound')
message: tpl(messages.pageNotFound)
}));
}

Expand Down Expand Up @@ -156,7 +161,7 @@ const privateBlogging = {
return res.redirect(urlUtils.urlFor({relativeUrl: forward}));
} else {
res.error = {
message: i18n.t('errors.middleware.privateblogging.wrongPassword')
message: tpl(messages.wrongPassword)
};
return next();
}
Expand Down
12 changes: 10 additions & 2 deletions core/frontend/helpers/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
// Usage: `{{asset "css/screen.css"}}`
//
// Returns the path to the specified asset.
const {SafeString, metaData, errors, i18n} = require('../services/proxy');
const {metaData} = require('../services/proxy');
const {SafeString} = require('../services/rendering');

const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const get = require('lodash/get');
const {getAssetUrl} = metaData;

const messages = {
pathIsRequired: 'The {{asset}} helper must be passed a path'
};

module.exports = function asset(path, options) {
const hasMinFile = get(options, 'hash.hasMinFile');

if (!path) {
throw new errors.IncorrectUsageError({
message: i18n.t('warnings.helpers.asset.pathIsRequired')
message: tpl(messages.pathIsRequired)
});
}

Expand Down
8 changes: 5 additions & 3 deletions core/frontend/helpers/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
//
// Block helper: `{{#author}}{{/author}}`
// This is the default handlebars behaviour of dropping into the author object scope
const {urlService, SafeString, escapeExpression, hbs, templates} = require('../services/proxy');
const buildInHelpers = hbs.handlebars.helpers;
const {urlService} = require('../services/proxy');
const {SafeString, escapeExpression, hbs, templates} = require('../services/rendering');
const isString = require('lodash/isString');

const builtInHelpers = hbs.handlebars.helpers;

/**
* @deprecated: single authors was superceded by multiple authors in Ghost 1.22.0
*/
module.exports = function author(options) {
if (options.fn) {
return buildInHelpers.with.call(this, this.author, options);
return builtInHelpers.with.call(this, this.author, options);
}

const autolink = isString(options.hash.autolink) && options.hash.autolink === 'false' ? false : true;
Expand Down
7 changes: 4 additions & 3 deletions core/frontend/helpers/authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// By default, authors are separated by commas.
//
// Note that the standard {{#each authors}} implementation is unaffected by this helper.
const {urlService} = require('../services/proxy');
const {SafeString, escapeExpression, templates} = require('../services/rendering');
const isString = require('lodash/isString');
const {SafeString, escapeExpression, templates, urlService} = require('../services/proxy');
const ghostHelperUtils = require('@tryghost/helpers').utils;
const {utils} = require('@tryghost/helpers');

module.exports = function authors(options = {}) {
options.hash = options.hash || {};
Expand Down Expand Up @@ -38,7 +39,7 @@ module.exports = function authors(options = {}) {
}) : escapeExpression(author.name);
}

return ghostHelperUtils.visibility.filter(authorsList, visibility, processAuthor);
return utils.visibility.filter(authorsList, visibility, processAuthor);
}

if (this.authors && this.authors.length) {
Expand Down
2 changes: 1 addition & 1 deletion core/frontend/helpers/body_class.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Usage: `{{body_class}}`
//
// Output classes for the body element
const {SafeString} = require('../services/proxy');
const {SafeString} = require('../services/rendering');

// We use the name body_class to match the helper for consistency
module.exports = function body_class(options) { // eslint-disable-line camelcase
Expand Down
11 changes: 9 additions & 2 deletions core/frontend/helpers/cancel_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
// Outputs cancel/renew links to manage subscription renewal after the subscription period ends.
//
// Defaults to class="cancel-subscription-link" errorClass="cancel-subscription-error" cancelLabel="Cancel subscription" continueLabel="Continue subscription"
const {labs} = require('../services/proxy');
const {templates} = require('../services/rendering');

const {templates, errors, i18n, labs} = require('../services/proxy');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');

const messages = {
invalidData: 'The {{cancel_link}} helper was used outside of a subscription context. See https://ghost.org/docs/themes/members/#cancel-links.'
};

function cancel_link(options) { // eslint-disable-line camelcase
let truncateOptions = (options || {}).hash || {};

if (this.id === undefined || this.cancel_at_period_end === undefined) {
throw new errors.IncorrectUsageError({message: i18n.t('warnings.helpers.cancel_link.invalidData')});
throw new errors.IncorrectUsageError({message: tpl(messages.invalidData)});
}

const data = {
Expand Down
2 changes: 1 addition & 1 deletion core/frontend/helpers/concat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {SafeString} = require('../services/proxy');
const {SafeString} = require('../services/rendering');

module.exports = function concat(...args) {
const options = args.pop();
Expand Down
2 changes: 1 addition & 1 deletion core/frontend/helpers/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
// Dev flag feature: In case of restricted content access for member-only posts, shows CTA box

const {templates, hbs, SafeString} = require('../services/proxy');
const {templates, hbs, SafeString} = require('../services/rendering');
const downsize = require('downsize');
const _ = require('lodash');
const createFrame = hbs.handlebars.createFrame;
Expand Down
2 changes: 1 addition & 1 deletion core/frontend/helpers/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Formats a date using moment-timezone.js. Formats published_at by default but will also take a date as a parameter

const {SafeString} = require('../services/proxy');
const {SafeString} = require('../services/rendering');
const moment = require('moment-timezone');
const _ = require('lodash');

Expand Down
2 changes: 1 addition & 1 deletion core/frontend/helpers/encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Returns URI encoded string

const {SafeString} = require('../services/proxy');
const {SafeString} = require('../services/rendering');

module.exports = function encode(string, options) {
const uri = string || options;
Expand Down
3 changes: 2 additions & 1 deletion core/frontend/helpers/excerpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//
// Defaults to words="50"

const {SafeString, metaData} = require('../services/proxy');
const {SafeString} = require('../services/rendering');
const {metaData} = require('../services/proxy');
const _ = require('lodash');
const getMetaDataExcerpt = metaData.getMetaDataExcerpt;

Expand Down
3 changes: 2 additions & 1 deletion core/frontend/helpers/facebook_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Usage: `{{facebook_url}}` or `{{facebook_url author.facebook}}`
//
// Output a url for a facebook username
const {socialUrls, localUtils} = require('../services/proxy');
const {socialUrls} = require('../services/proxy');
const {localUtils} = require('../services/rendering');

// We use the name facebook_url to match the helper for consistency:
module.exports = function facebook_url(username, options) { // eslint-disable-line camelcase
Expand Down
Loading

0 comments on commit 1571e4e

Please sign in to comment.