mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-01 23:37:43 +03:00
Updated local config helpers bind pattern
- The new @tryghost/config-url-helpers has a pattern of exposing bindAll() - Changed the local (non url) helpers to have the same pattern for consistency - Also fixed types as best I can
This commit is contained in:
parent
6aafb735b1
commit
8cf411e524
@ -1,5 +1,10 @@
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* @callback isPrivacyDisabledFn
|
||||
* @param {string} privacyFlag - the flag to be looked up
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
||||
if (!this.get('privacy')) {
|
||||
return false;
|
||||
@ -19,7 +24,9 @@ const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
||||
};
|
||||
|
||||
/**
|
||||
* we can later support setting folder names via custom config values
|
||||
* @callback getContentPathFn
|
||||
* @param {string} type - the type of context you want the path for
|
||||
* @returns {string}
|
||||
*/
|
||||
const getContentPath = function getContentPath(type) {
|
||||
switch (type) {
|
||||
@ -43,7 +50,12 @@ const getContentPath = function getContentPath(type) {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
isPrivacyDisabled,
|
||||
getContentPath
|
||||
/**
|
||||
* @typedef ConfigHelpers
|
||||
* @property {isPrivacyDisabledFn} isPrivacyDisabled
|
||||
* @property {getContentPathFn} getContentPath
|
||||
*/
|
||||
module.exports.bindAll = (nconf) => {
|
||||
nconf.isPrivacyDisabled = isPrivacyDisabled.bind(nconf);
|
||||
nconf.getContentPath = getContentPath.bind(nconf);
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ const env = process.env.NODE_ENV || 'development';
|
||||
|
||||
/**
|
||||
* @param {object} options
|
||||
* @returns {Nconf.Provider & urlHelpers.BoundHelpers}
|
||||
* @returns {Nconf.Provider & urlHelpers.BoundHelpers & helpers.ConfigHelpers}
|
||||
*/
|
||||
function loadNconf(options) {
|
||||
debug('config start');
|
||||
@ -50,8 +50,7 @@ function loadNconf(options) {
|
||||
nconf.checkUrlProtocol = localUtils.checkUrlProtocol.bind(nconf);
|
||||
|
||||
// Expose dynamic utility methods
|
||||
nconf.isPrivacyDisabled = helpers.isPrivacyDisabled.bind(nconf);
|
||||
nconf.getContentPath = helpers.getContentPath.bind(nconf);
|
||||
helpers.bindAll(nconf);
|
||||
urlHelpers.bindAll(nconf);
|
||||
|
||||
// ## Sanitization
|
||||
|
Loading…
Reference in New Issue
Block a user