gatsby-theme-advanced
Version:
GatsbyJS theme equipped with advanced features.
35 lines (34 loc) • 1.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const is_absolute_url_1 = __importDefault(require("is-absolute-url"));
// Validate
const validateSiteConfig = (config) => {
const newConfig = config;
// Make sure pathPrefix is empty if not needed
if (newConfig.pathPrefix === "/") {
newConfig.pathPrefix = "";
}
else {
// Make sure pathPrefix only contains the first forward slash
newConfig.pathPrefix = `/${newConfig.pathPrefix.replace(/^\/|\/$/g, "")}`;
}
// Make sure website.url doesn't have an ending forward slash
if (newConfig.website.url.substr(-1) === "/")
newConfig.website.url = newConfig.website.url.slice(0, -1);
// Make sure website.rss has a starting forward slash
if (newConfig.website.rss && newConfig.website.rss[0] !== "/")
newConfig.website.rss = `/${newConfig.website.rss}`;
// Make sure that website.url is an absolute URL
if (!(0, is_absolute_url_1.default)(newConfig.website.url)) {
throw new Error("SiteConfig.website.url is not absolute.");
}
// Make sure that organization.url is an absolute URL
if (newConfig.organization && !(0, is_absolute_url_1.default)(newConfig.organization.url)) {
throw new Error("SiteConfig.organization.url is not absolute.");
}
return newConfig;
};
exports.default = validateSiteConfig;