Commits: 6
Parse /index.html URL into Home route
Otherwise it's treated as Content /index. The most visible effect is
that the navigation bar is displayed. On Home route it should not be.
index 8dbac32..a1a6bbf 100644
--- a/src/Routes.elm
+++ b/src/Routes.elm
@@ -20,6 +20,7 @@ parser : Parser (Route -> b) b
=parser =
= Parser.oneOf
= [ Parser.map Home Parser.top
+ , Parser.map Home (Parser.s "index.html")
= , Parser.map Motivation (Parser.s "motivation.html")
= , Parser.map TestRun (Parser.s "test-run.html")
= , Parser.custom "Content"Change port of the capture server to 8010
To avoid clashes with Elm Reactor.
index 1c73baa..ea95984 100644
--- a/src/capture.coffee
+++ b/src/capture.coffee
@@ -4,6 +4,8 @@ FS = require "fs"
=glob = require "glob"
=Path = require "path"
=
+port = 8010
+
=match = (pattern, options) =>
= new Promise (resolve, reject) =>
= glob pattern, options, (error, paths) =>
@@ -17,7 +19,7 @@ do () =>
= app.get '*', (req, res) ->
= res.sendFile "container.html", root: process.cwd ``
=
- server = app.listen 8000
+ server = app.listen port
=
= browser = await puppeteer.launch
= args: [
@@ -32,7 +34,7 @@ do () =>
= { dir, name } = Path.parse match
= base = if dir is "" then name else "#{dir}/#{name}"
=
- url = "http://localhost:8000/#{base}.html"
+ url = "http://localhost:#{port}/#{base}.html"
= path = "built/captured/#{base}.html"
=
= await page.goto url, waitUntil: "networkidle2"Crash the capture process if there is an error on page being captured
Also console log messages from the page to standard output. Some additional logging is commented out for future debugging.
index ea95984..c98f206 100644
--- a/src/capture.coffee
+++ b/src/capture.coffee
@@ -29,6 +29,17 @@ do () =>
=
= page = await browser.newPage ``
=
+ page.on "pageerror", (error) ->
+ console.error error
+ process.exit 1
+
+ # page.on "response", (response) ->
+ # console.log "#{response.status ``} #{response.url ``}"
+
+ page.on "console", (msg) ->
+ console.log "# #{page.url ``}: #{msg.text ``}"
+
+
= for match in await match "*.txt", cwd: "content/"
= await do (match) ->
= { dir, name } = Path.parse match
@@ -37,8 +48,11 @@ do () =>
= url = "http://localhost:#{port}/#{base}.html"
= path = "built/captured/#{base}.html"
=
+ # console.log ""
+ # console.log "<-- Catpuring #{url}"
= await page.goto url, waitUntil: "networkidle2"
=
+
= html =
= (await page.content ``)
= .replace /<p\b/gi, "<div"
@@ -51,6 +65,12 @@ do () =>
= </body>
= """
=
+ # console.log ""
+ # console.log html
+ # console.log ""
+
+ # console.log "--> Writing to #{path}"
+
= await new Promise (resolve, reject) ->
= FS.writeFile path, html, (error) ->
= if error then return reject errorFix #23: flash of Loading view
In capture.coffee the markup is now baked into captured HTML and when the page loads it is passed to the Elm program as flags. If it's correctly parsed, then the program starts in the Loaded state and there is no flash. Also there is no need to make additional request from init!
index b2d458d..c0abf0b 100644
--- a/container.html
+++ b/container.html
@@ -22,7 +22,7 @@
= <!-- <div id="app-container"></div> -->
= <script src="/built/index.js"></script>
= <script>
- Elm.Main.init()
+ Elm.Main.init({ flags: { markup: null } })
= </script>
= </body>
=</html>index e4b5db2..41c32c3 100644
--- a/src/Main.elm
+++ b/src/Main.elm
@@ -68,7 +68,8 @@ main =
=
=
=type alias Flags =
- ()
+ { markup : Maybe String
+ }
=
=
=type alias Model =
@@ -118,19 +119,34 @@ init flags url key =
= let
= ( examplesModel, examplesCmd ) =
= Examples.init
+
+ content =
+ case flags.markup of
+ Nothing ->
+ Loading
+
+ Just markup ->
+ markup
+ |> Mark.parse document
+ |> Result.map Loaded
+ |> Result.extract ParseError
= in
= ( { location = url
= , key = key
- , content = Loading
+ , content = content
= , examples = examplesModel
= , scroll = 0
= , viewport =
= { width = 800, height = 600 }
= }
= , Cmd.batch
- [ url
- |> Routes.parse
- |> loadContent
+ [ if content == Loading then
+ url
+ |> Routes.parse
+ |> loadContent
+
+ else
+ Cmd.none
= , Dom.getViewport
= |> Task.map
= (\{ viewport } ->index c98f206..1149557 100644
--- a/src/capture.coffee
+++ b/src/capture.coffee
@@ -42,6 +42,12 @@ do () =>
=
= for match in await match "*.txt", cwd: "content/"
= await do (match) ->
+ markup = await new Promise (resolve, reject) ->
+ FS.readFile "content/" + match, encoding: "utf-8", (error, content) ->
+ if error then return reject error
+
+ resolve content
+
= { dir, name } = Path.parse match
= base = if dir is "" then name else "#{dir}/#{name}"
=
@@ -60,7 +66,8 @@ do () =>
= .replace "</body>", """
= <script src="/built/index.js"></script>
= <script>
- Elm.Main.init()
+ var flags = { markup : #{ JSON.stringify markup } }
+ Elm.Main.init({ flags: flags })
= </script>
= </body>
= """Enable compiler optimization in build script
index b3c69f2..c8408b6 100755
--- a/scripts/build
+++ b/scripts/build
@@ -9,7 +9,7 @@ mkdir -p built/
=mkdir -p public/
=
=
-npx elm make src/Main.elm --output built/index.js
+npx elm make src/Main.elm --output built/index.js --optimize
=
=
=cp -r content/ public/content/Merge branch '23-there-is-a-flash-of-loading-content-right-after-opening-first-page' into 'master'
Resolve "There is a flash of "Loading content" right after opening first page"
Closes #23
See merge request software-garden/software-garden.gitlab.io!28