diff --git a/generator/src/elm-file-constants.js b/generator/src/elm-file-constants.js index b9e3211a..c16aba8c 100644 --- a/generator/src/elm-file-constants.js +++ b/generator/src/elm-file-constants.js @@ -1,5 +1,5 @@ const exposingList = - "(application, PageRoute, all, pages, routeToString, Image, imageUrl, images)"; + "(application, PageRoute, all, pages, routeToString, Image, imageUrl, images, allImages)"; function staticRouteStuff(staticRoutes) { return ` @@ -21,6 +21,11 @@ ${staticRoutes.urlParser} ${staticRoutes.imageAssetsRecord} +allImages : List Image +allImages = + [${staticRoutes.allImages.join("\n , ")} + ] + routeToString : PageRoute -> String routeToString (PageRoute route) = "/" diff --git a/generator/src/generate-records.js b/generator/src/generate-records.js index 2ccfa489..38e8c027 100644 --- a/generator/src/generate-records.js +++ b/generator/src/generate-records.js @@ -101,7 +101,8 @@ function generate(scanned) { // routeToMetadata: formatCaseStatement("toMetadata", routeToMetadata), // routeToDocExtension: formatCaseStatement("toExt", routeToExt), // routeToSource: formatCaseStatement("toSourcePath", routeToSource), - imageAssetsRecord: toElmRecord("images", getImageAssets(), true) + imageAssetsRecord: toElmRecord("images", getImageAssets(), true), + allImages: allImageAssetNames() }; } function getImageAssets() { @@ -123,6 +124,21 @@ function getImageAssets() { }); return assetsRecord; } +function allImageAssetNames() { + return glob + .sync("images/**/*", {}) + .filter(filePath => !fs.lstatSync(filePath).isDirectory()) + .map(relativeImagePath) + .map(info => { + return ( + "(Image [ " + + info.fragmentsWithExtension + .map(fragment => `"${fragment}"`) + .join(", ") + + " ])" + ); + }); +} function toPascalCase(str) { var pascal = str.replace(/(\-\w)/g, function(m) { return m[1].toUpperCase();