From 8408ac60d5d9a61d4a5554d9e15dce932e13048c Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 21 Aug 2019 21:08:56 -0700 Subject: [PATCH] Fix static routes for prerendering. --- generator/src/elm-pages.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/generator/src/elm-pages.js b/generator/src/elm-pages.js index 1a1354a9..84ec86b0 100755 --- a/generator/src/elm-pages.js +++ b/generator/src/elm-pages.js @@ -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("/")}`; +}