Fix static routes for prerendering.

This commit is contained in:
Dillon Kearns 2019-08-21 21:08:56 -07:00
parent e770d19254
commit 8408ac60d5

View File

@ -102,6 +102,7 @@ function run() {
app.ports.writeFile.subscribe(contents => {
const rawContent = generateRawContent(markdownContent, content);
const routes = toRoutes(markdownContent.concat(content));
fs.writeFileSync("./gen/RawContent.elm", rawContent);
fs.writeFileSync("./gen/PagesNew.elm", elmPagesUiFile(staticRoutes));
@ -112,7 +113,7 @@ function run() {
if (!devServerRunning) {
devServerRunning = true;
develop.start({
routes: contents.routes,
routes,
debug: contents.debug,
manifestConfig
});
@ -120,7 +121,7 @@ function run() {
} else {
develop.run(
{
routes: contents.routes,
routes,
manifestConfig
},
() => {}
@ -149,3 +150,16 @@ function startWatchIfNeeded() {
});
}
}
function toRoutes(entries) {
return entries.map(toRoute);
}
function toRoute(entry) {
let fullPath = entry.path
.replace(/(index)?\.[^/.]+$/, "")
.split("/")
.filter(item => item !== "");
fullPath.splice(0, 1);
return `/${fullPath.join("/")}`;
}