Added JSDocs to redirects validator

refs https://github.com/TryGhost/Toolbox/issues/139

- Makes the expected file formatting easier to reason about
This commit is contained in:
Naz 2021-11-25 14:49:06 +04:00 committed by naz
parent 6ed5f64f4b
commit b807be9699
2 changed files with 11 additions and 1 deletions

View File

@ -217,7 +217,7 @@ class CustomRedirectsAPI {
const redirectsFilePath = await this.getRedirectsFilePath();
if (redirectsFilePath) {
const backupRedirectsPath = getBackupRedirectsFilePath(redirectsFilePath);
const backupRedirectsPath = this.getBackupFilePath(redirectsFilePath);
const backupExists = await fs.pathExists(backupRedirectsPath);
if (backupExists) {

View File

@ -7,9 +7,19 @@ const messages = {
invalidRedirectsFromRegex: 'Incorrect RegEx in redirects file.',
redirectsHelp: 'https://ghost.org/docs/themes/routing/#redirects'
};
/**
* Redirect configuration object
* @typedef {Object} RedirectConfig
* @property {String} from - Defines the relative incoming URL or pattern (regex)
* @property {String} to - Defines where the incoming traffic should be redirected to, which can be a static URL, or a dynamic value using regex (example: "to": "/$1/")
* @property {boolean} [permanent] - Can be defined with true for a permanent HTTP 301 redirect, or false for a temporary HTTP 302 redirect
*/
/**
* Redirects are file based at the moment, but they will live in the database in the future.
* See V2 of https://github.com/TryGhost/Ghost/issues/7707.
* @param {RedirectConfig[]} redirects
*/
const validate = (redirects) => {
if (!_.isArray(redirects)) {