1
Fork 0

Add accounts to context

This commit is contained in:
Jake Howard 2019-06-29 18:22:14 +01:00
parent 841ca7af44
commit 3541719aee
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 32 additions and 1 deletions

7
accounts.yml Normal file
View file

@ -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

View file

@ -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<Account> = 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.`);
})();

5
package-lock.json generated
View file

@ -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",

View file

@ -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",