Commits: 3
Rename capture script to build
This name better reflects it's function.
index 8ae0061..801b12d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,3 +1,4 @@
+
=image: alekzonder/puppeteer:1.8.0-0
=
=before_script:
@@ -6,7 +7,7 @@ before_script:
=pages:
= stage: deploy
= script:
- - scripts/capture
+ - scripts/build
=
= artifacts:
= paths:similarity index 99%
rename from scripts/capture
rename to scripts/build
index 4236c08..d9def3c 100755
--- a/scripts/capture
+++ b/scripts/build
@@ -2,6 +2,7 @@
=
=set -euo pipefail
=
+
=rm -rf built/
=rm -rf public/
=mkdir -p built/
@@ -15,6 +16,7 @@ cp -r content/ public/content/
=cp -r assets/ public/assets/
=cp -r built/* public/assets/
=
+
=mkdir -p built/captured/
=npx coffee src/capture.coffee
=cp -r built/captured/* public/Make capture.coffee automatically scan for content/*.txt files
index 0ce2b31..b00bfa5 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
= "elm": "^0.19.0-bugfix2",
= "elm-live": "^3.4.0",
= "express": "^4.16.4",
+ "glob": "^7.1.3",
= "puppeteer": "^1.11.0"
= }
=}index 46eae85..bdbd6c6 100644
--- a/src/capture.coffee
+++ b/src/capture.coffee
@@ -1,6 +1,14 @@
=puppeteer = require "puppeteer"
=express = require "express"
-fs = require "fs"
+FS = require "fs"
+glob = require "glob"
+Path = require "path"
+
+match = (pattern, options) =>
+ new Promise (resolve, reject) =>
+ glob pattern, options, (error, paths) =>
+ if error then return reject errro
+ resolve paths
=
=do () =>
= app = express ``
@@ -19,14 +27,11 @@ do () =>
=
= page = await browser.newPage ``
=
- # TODO: Scan the directory and make this list dynamic!
- for base in [
- "index",
- "preparation",
- "day-1",
- "rest"
- ]
- await do (base) ->
+ for match in await match "*.txt", cwd: "content/"
+ await do (match) ->
+ { dir, name } = Path.parse match
+ base = if dir is "" then name else "#{dir}/#{name}"
+
= url = "http://localhost:8000/#{base}.html"
= path = "built/captured/#{base}.html"
=
@@ -42,7 +47,7 @@ do () =>
= """
=
= await new Promise (resolve, reject) ->
- fs.writeFile path, html, (error) ->
+ FS.writeFile path, html, (error) ->
= if error then return reject error
= do resolve
=Disable pages CI task on branches different than master
index 801b12d..4472935 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -12,5 +12,6 @@ pages:
= artifacts:
= paths:
= - public
- # only:
- # - master
+
+ only:
+ - master