From 1fb98e86501b5c48bccdd80788667329cf2511c8 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 24 Jul 2019 15:22:04 -0700 Subject: [PATCH] Write image-assets file. --- generator/src/Main.elm | 9 ++++++++- generator/src/elm-static-markup.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/generator/src/Main.elm b/generator/src/Main.elm index e4584b51..15408d1a 100644 --- a/generator/src/Main.elm +++ b/generator/src/Main.elm @@ -5,7 +5,7 @@ import Cli.Program as Program import String.Interpolate exposing (interpolate) -port writeFile : { rawContent : String, prerenderrc : String } -> Cmd msg +port writeFile : { rawContent : String, prerenderrc : String, imageAssets : String } -> Cmd msg port printAndExitSuccess : String -> Cmd msg @@ -130,6 +130,13 @@ init flags Default = { rawContent = generate { pages = flags.pages, posts = flags.posts } , prerenderrc = preRenderRc { pages = flags.pages, posts = flags.posts } + , imageAssets = """export const imageAssets = { + "dillon2.jpg": require("../../images/dillon2.jpg"), + "article-cover/exit.jpg": require("../../images/article-cover/exit.jpg"), + "article-cover/mountains.jpg": require("../../images/article-cover/mountains.jpg"), + "article-cover/thinker.jpg": require("../../images/article-cover/thinker.jpg") +}; +""" } |> writeFile diff --git a/generator/src/elm-static-markup.ts b/generator/src/elm-static-markup.ts index a813efe9..20b614e2 100644 --- a/generator/src/elm-static-markup.ts +++ b/generator/src/elm-static-markup.ts @@ -10,6 +10,7 @@ function unpackFile(path: string) { const posts = glob.sync("_posts/**/*.emu", {}).map(unpackFile); const pages = glob.sync("_pages/**/*.emu", {}).map(unpackFile); +const images = glob.sync("images/**/*", {}); let app = Elm.Main.init({ flags: { argv: process.argv, versionMessage: version, posts, pages } @@ -26,8 +27,14 @@ app.ports.printAndExitFailure.subscribe((message: string) => { }); app.ports.writeFile.subscribe( - (contents: { rawContent: string; prerenderrc: string }) => { + (contents: { + rawContent: string; + prerenderrc: string; + imageAssets: string; + }) => { fs.writeFileSync("./gen/RawContent.elm", contents.rawContent); fs.writeFileSync("./.prerenderrc", contents.prerenderrc); + console.log("image assets", contents.imageAssets); + fs.writeFileSync("./src/js/image-assets.js", contents.imageAssets); } );