react-odyssey
Version:
React components for Odyssey design system
43 lines (34 loc) • 890 B
JavaScript
export const hashRE = /#.*$/;
export const extRE = /\.(md|html)$/;
export const endingSlashRE = /\/$/;
export const outboundRE = /^[a-z]+:/i;
export function normalize(path) {
return decodeURI(path)
.replace(hashRE, "")
.replace(extRE, "");
}
export function isExternal(path) {
return outboundRE.test(path);
}
export function isMailto(path) {
return /^mailto:/.test(path);
}
export function isTel(path) {
return /^tel:/.test(path);
}
export function ensureExt(path) {
if (isExternal(path)) {
return path;
}
const hashMatch = path.match(hashRE);
const hash = hashMatch ? hashMatch[0] : "";
const normalized = normalize(path);
if (endingSlashRE.test(normalized)) {
return path;
}
return normalized + ".html" + hash;
}
export function resolveNav(page, regularPath, site, localePath) {
const { themeConfig } = site;
return themeConfig.nav;
}