ported to static site, removed _ext folder, split hbs files into partials

This commit is contained in:
skeddles
2021-07-06 17:24:20 -04:00
parent 1e3549b016
commit 1f820fd97e
86 changed files with 1203 additions and 977 deletions

41
helpers/svg.js Normal file
View File

@@ -0,0 +1,41 @@
const fs = require("fs");
const handlebars = require("handlebars");
const ltx = require("ltx");
const resolve = require("resolve");
const path = "../svg/";
const nameToModule = {};
const cache = {};
module.exports = function (name, opts) {
name = path + name;
const mod =
nameToModule[name] ||
(nameToModule[name] = resolve.sync(name, {
extensions: [".svg"],
}));
const content =
cache[name] || (cache[name] = fs.readFileSync(mod, "utf-8"));
const svg = parse(content);
Object.assign(svg.attrs, opts.hash);
return new handlebars.SafeString(svg.root().toString());
};
module.exports.cache = cache;
function parse(xml, mod) {
const svg = ltx.parse(xml);
if (svg.name != "svg") {
throw new TypeError("Input must be an SVG");
}
delete svg.attrs.xmlns;
delete svg.attrs["xmlns:xlink"];
return svg;
}