From 3541719aee6812910bc77460f55864ae1863299a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 29 Jun 2019 18:22:14 +0100 Subject: [PATCH] Add accounts to context --- accounts.yml | 7 +++++++ index.ts | 19 ++++++++++++++++++- package-lock.json | 5 +++++ package.json | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 accounts.yml diff --git a/accounts.yml b/accounts.yml new file mode 100644 index 0000000..c8ca808 --- /dev/null +++ b/accounts.yml @@ -0,0 +1,7 @@ +PayPal: + image: https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/PayPal_Logo_Icon_2014.svg/887px-PayPal_Logo_Icon_2014.svg.png + link: https://www.paypal.me/TheOrangeOne + +Monzo: + image: https://upload.wikimedia.org/wikipedia/en/thumb/a/a3/Monzo_logo.svg/1920px-Monzo_logo.svg.png + link: https://monzo.me/jakehoward diff --git a/index.ts b/index.ts index 94e02ad..0e4a270 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,7 @@ import { readFileSync, writeFileSync } from 'fs'; import glob from 'glob'; import Handlebars from 'handlebars'; +import jsyaml from 'js-yaml'; import mkdirp from 'mkdirp'; import Bundler from 'parcel-bundler'; import { dirname, join } from 'path'; @@ -8,6 +9,13 @@ import ProgressBar from 'progress'; import rimraf from 'rimraf'; import { range } from 'underscore'; +interface Account { + image: string; + link: string; +} + + + const BUILD_DIR = join(__dirname, 'build'); const SRC_DIR = join(__dirname, 'src'); const PROGRESS_BAR_FORMAT = '[:bar] :rate/ps :percent :current/:total'; @@ -21,6 +29,7 @@ const BUNDLER_OPTIONS = { minify: true, }; + function statusOutput(message: string) { console.log('> ' + message + '...'); } @@ -42,6 +51,9 @@ function writeTemplate( (async function() { rimraf.sync(BUILD_DIR); + statusOutput("Reading accounts") + const accounts: ReadonlyArray = jsyaml.safeLoad(readFileSync(join(__dirname, 'accounts.yml')).toString()); + statusOutput('Creating template'); const bundler = new Bundler(join(SRC_DIR, 'template.html'), BUNDLER_OPTIONS); await bundler.bundle(); @@ -57,11 +69,16 @@ function writeTemplate( width: 40, }); + const baseContext = { + accounts + }; + statusOutput('Generating pages'); possibleValues.forEach(i => { if (i) { const value = parseFloat(i.toFixed(2)); const context = { + ...baseContext, value: value.toFixed(2), }; writeTemplate(template, value.toString(), context); @@ -74,7 +91,7 @@ function writeTemplate( } bar.tick(); }); - writeTemplate(template, '', {value: ''}); + writeTemplate(template, '', {...baseContext, value: ''}); const filesOutput = glob.sync(join(BUILD_DIR, "**/index.html")).length; console.log(`Generated ${filesOutput} files.`); })(); diff --git a/package-lock.json b/package-lock.json index 8ecba16..ebbe1e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1048,6 +1048,11 @@ "@types/node": "*" } }, + "@types/js-yaml": { + "version": "3.12.1", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.12.1.tgz", + "integrity": "sha512-SGGAhXLHDx+PK4YLNcNGa6goPf9XRWQNAUUbffkwVGGXIxmDKWyGGL4inzq2sPmExu431Ekb9aEMn9BkPqEYFA==" + }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", diff --git a/package.json b/package.json index fb2115d..344e874 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "homepage": "https://github.com/RealOrangeOne/givemoneyto.me#readme", "dependencies": { "@fortawesome/fontawesome-free": "5.7.1", + "@types/js-yaml": "^3.12.1", "@types/mkdirp": "^0.5.2", "@types/node": "^12.0.10", "@types/parcel-bundler": "^1.12.0", @@ -28,6 +29,7 @@ "bootstrap": "4.2.1", "glob": "^7.1.4", "handlebars": "^4.1.2", + "js-yaml": "^3.13.1", "mkdirp": "^0.5.1", "parcel-bundler": "1.12.3", "prettier": "^1.18.2",