antwar
Version:
A static site engine built with React and Webpack
20 lines (14 loc) • 406 B
JavaScript
;
const _ = require("lodash");
module.exports = function getPageForPath(path, pages) {
if (path === "/") {
return pages["/"] || {};
}
// Paths don't have trailing slashes so try without
const ret = pages[path] || pages[_.trimEnd(path, "/")];
if (!ret) {
console.warn("getPageForPath - No match!", path, Object.keys(pages).join(", "));
return {};
}
return ret;
};