mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
parent
f69526c140
commit
fae05558f3
1 changed files with 20 additions and 0 deletions
|
@ -9,6 +9,14 @@ const config = require('../../../shared/config');
|
||||||
const {i18n} = require('../../../server/lib/common');
|
const {i18n} = require('../../../server/lib/common');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
const readRedirectsFile = (redirectsPath) => {
|
const readRedirectsFile = (redirectsPath) => {
|
||||||
return fs.readFile(redirectsPath, 'utf-8')
|
return fs.readFile(redirectsPath, 'utf-8')
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -26,6 +34,13 @@ const readRedirectsFile = (redirectsPath) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {String} content serialized JSON or YAML configuration
|
||||||
|
* @param {String} ext one of `.json` or `.yaml` extensions
|
||||||
|
*
|
||||||
|
* @returns {RedirectConfig[]} of parsed redirect config objects
|
||||||
|
*/
|
||||||
const parseRedirectsFile = (content, ext) => {
|
const parseRedirectsFile = (content, ext) => {
|
||||||
if (ext === '.json') {
|
if (ext === '.json') {
|
||||||
let redirects;
|
let redirects;
|
||||||
|
@ -189,6 +204,11 @@ const get = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Syncrounously loads current oncifg file and parses it's content
|
||||||
|
*
|
||||||
|
* @returns {{RedirectConfig[]}} of parsed redirect configurations
|
||||||
|
*/
|
||||||
const loadRedirectsFile = () => {
|
const loadRedirectsFile = () => {
|
||||||
const filePath = getCurrentRedirectsFilePathSync();
|
const filePath = getCurrentRedirectsFilePathSync();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue