mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
23 lines
665 B
JavaScript
23 lines
665 B
JavaScript
![]() |
import { promises as fs } from "fs";
|
||
|
import path from "path";
|
||
|
import yaml from "js-yaml";
|
||
|
import checkAndCopyConfig from "utils/config";
|
||
|
|
||
|
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) => {
|
||
|
return {
|
||
|
type: Object.keys(group)[0],
|
||
|
options: { ...group[Object.keys(group)[0]] },
|
||
|
};
|
||
|
});
|
||
|
|
||
|
res.send(widgetsArray);
|
||
|
}
|