Add accounts to context
This commit is contained in:
parent
841ca7af44
commit
3541719aee
4 changed files with 32 additions and 1 deletions
7
accounts.yml
Normal file
7
accounts.yml
Normal 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
|
19
index.ts
19
index.ts
|
@ -1,6 +1,7 @@
|
||||||
import { readFileSync, writeFileSync } from 'fs';
|
import { readFileSync, writeFileSync } from 'fs';
|
||||||
import glob from 'glob';
|
import glob from 'glob';
|
||||||
import Handlebars from 'handlebars';
|
import Handlebars from 'handlebars';
|
||||||
|
import jsyaml from 'js-yaml';
|
||||||
import mkdirp from 'mkdirp';
|
import mkdirp from 'mkdirp';
|
||||||
import Bundler from 'parcel-bundler';
|
import Bundler from 'parcel-bundler';
|
||||||
import { dirname, join } from 'path';
|
import { dirname, join } from 'path';
|
||||||
|
@ -8,6 +9,13 @@ import ProgressBar from 'progress';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
import { range } from 'underscore';
|
import { range } from 'underscore';
|
||||||
|
|
||||||
|
interface Account {
|
||||||
|
image: string;
|
||||||
|
link: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const BUILD_DIR = join(__dirname, 'build');
|
const BUILD_DIR = join(__dirname, 'build');
|
||||||
const SRC_DIR = join(__dirname, 'src');
|
const SRC_DIR = join(__dirname, 'src');
|
||||||
const PROGRESS_BAR_FORMAT = '[:bar] :rate/ps :percent :current/:total';
|
const PROGRESS_BAR_FORMAT = '[:bar] :rate/ps :percent :current/:total';
|
||||||
|
@ -21,6 +29,7 @@ const BUNDLER_OPTIONS = {
|
||||||
minify: true,
|
minify: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function statusOutput(message: string) {
|
function statusOutput(message: string) {
|
||||||
console.log('> ' + message + '...');
|
console.log('> ' + message + '...');
|
||||||
}
|
}
|
||||||
|
@ -42,6 +51,9 @@ function writeTemplate(
|
||||||
(async function() {
|
(async function() {
|
||||||
rimraf.sync(BUILD_DIR);
|
rimraf.sync(BUILD_DIR);
|
||||||
|
|
||||||
|
statusOutput("Reading accounts")
|
||||||
|
const accounts: ReadonlyArray<Account> = jsyaml.safeLoad(readFileSync(join(__dirname, 'accounts.yml')).toString());
|
||||||
|
|
||||||
statusOutput('Creating template');
|
statusOutput('Creating template');
|
||||||
const bundler = new Bundler(join(SRC_DIR, 'template.html'), BUNDLER_OPTIONS);
|
const bundler = new Bundler(join(SRC_DIR, 'template.html'), BUNDLER_OPTIONS);
|
||||||
await bundler.bundle();
|
await bundler.bundle();
|
||||||
|
@ -57,11 +69,16 @@ function writeTemplate(
|
||||||
width: 40,
|
width: 40,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const baseContext = {
|
||||||
|
accounts
|
||||||
|
};
|
||||||
|
|
||||||
statusOutput('Generating pages');
|
statusOutput('Generating pages');
|
||||||
possibleValues.forEach(i => {
|
possibleValues.forEach(i => {
|
||||||
if (i) {
|
if (i) {
|
||||||
const value = parseFloat(i.toFixed(2));
|
const value = parseFloat(i.toFixed(2));
|
||||||
const context = {
|
const context = {
|
||||||
|
...baseContext,
|
||||||
value: value.toFixed(2),
|
value: value.toFixed(2),
|
||||||
};
|
};
|
||||||
writeTemplate(template, value.toString(), context);
|
writeTemplate(template, value.toString(), context);
|
||||||
|
@ -74,7 +91,7 @@ function writeTemplate(
|
||||||
}
|
}
|
||||||
bar.tick();
|
bar.tick();
|
||||||
});
|
});
|
||||||
writeTemplate(template, '', {value: ''});
|
writeTemplate(template, '', {...baseContext, value: ''});
|
||||||
const filesOutput = glob.sync(join(BUILD_DIR, "**/index.html")).length;
|
const filesOutput = glob.sync(join(BUILD_DIR, "**/index.html")).length;
|
||||||
console.log(`Generated ${filesOutput} files.`);
|
console.log(`Generated ${filesOutput} files.`);
|
||||||
})();
|
})();
|
||||||
|
|
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -1048,6 +1048,11 @@
|
||||||
"@types/node": "*"
|
"@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": {
|
"@types/minimatch": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
"homepage": "https://github.com/RealOrangeOne/givemoneyto.me#readme",
|
"homepage": "https://github.com/RealOrangeOne/givemoneyto.me#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "5.7.1",
|
"@fortawesome/fontawesome-free": "5.7.1",
|
||||||
|
"@types/js-yaml": "^3.12.1",
|
||||||
"@types/mkdirp": "^0.5.2",
|
"@types/mkdirp": "^0.5.2",
|
||||||
"@types/node": "^12.0.10",
|
"@types/node": "^12.0.10",
|
||||||
"@types/parcel-bundler": "^1.12.0",
|
"@types/parcel-bundler": "^1.12.0",
|
||||||
|
@ -28,6 +29,7 @@
|
||||||
"bootstrap": "4.2.1",
|
"bootstrap": "4.2.1",
|
||||||
"glob": "^7.1.4",
|
"glob": "^7.1.4",
|
||||||
"handlebars": "^4.1.2",
|
"handlebars": "^4.1.2",
|
||||||
|
"js-yaml": "^3.13.1",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"parcel-bundler": "1.12.3",
|
"parcel-bundler": "1.12.3",
|
||||||
"prettier": "^1.18.2",
|
"prettier": "^1.18.2",
|
||||||
|
|
Reference in a new issue