Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const template = nodePath.resolve(page)
// Make sure the path is relative to the location root
let path = nodePath.relative(location, template)
// Cutoff the extension
path = nodePath.join(
nodePath.dirname(path),
nodePath.basename(path, nodePath.extname(path))
)
// Ensure paths are unix
path = path.split(nodePath.sep).join(nodePath.posix.sep)
// Make sure it starts with a slash
path = path[0] === '/' ? path : `/${path}`
// Turn `/index` paths into roots`
path = path.replace(/\/index$/, '/')
// Add the path prefix
path = pathPrefix ? pathJoin(pathPrefix, path) : path
// Return the route
return createRoute({
path,
template,
originalPath,
})
})
)
export function getPermaLink(path, prefixPath) {
const permalink = `${prefixPath}${pathJoin(path)}`
return `${permalink}/`.replace(REGEX_TO_GET_LAST_SLASH, '/')
}