utils cleanup, initial static generation

This commit is contained in:
Ben Phelps 2022-09-26 12:04:37 +03:00
parent ec8700f3e9
commit e1a3a82f75
86 changed files with 279 additions and 261 deletions

View file

@ -1,22 +1,5 @@
import { promises as fs } from "fs";
import path from "path";
import yaml from "js-yaml";
import checkAndCopyConfig from "utils/config";
import { widgetsResponse } from "utils/config/api-response";
export default async function handler(req, res) {
checkAndCopyConfig("widgets.yaml");
const widgetsYaml = path.join(process.cwd(), "config", "widgets.yaml");
const fileContents = await fs.readFile(widgetsYaml, "utf8");
const widgets = yaml.load(fileContents);
// map easy to write YAML objects into easy to consume JS arrays
const widgetsArray = widgets.map((group) => ({
type: Object.keys(group)[0],
options: { ...group[Object.keys(group)[0]] },
}));
res.send(widgetsArray);
res.send(await widgetsResponse());
}