diff --git a/docs/_data/datatypes.js b/docs/_data/datatypes.js new file mode 100644 index 000000000..fb044bbf6 --- /dev/null +++ b/docs/_data/datatypes.js @@ -0,0 +1,66 @@ +const { readdir, readFile } = require("node:fs/promises"); +const path = require("path"); + +async function fetchFile(location) { + return readFile(location, { encoding: "utf8" }).then((file) => + JSON.parse(file) + ); +} + +async function fetchData(dir) { + try { + const files = await readdir(dir); + console.log(files.length); + let result = await Promise.all( + files.map(async (file) => { + return await fetchFile(path.join(dir, file)); + }) + ); + return result; + } catch (err) { + throw err; + } +} + +function sortData(typesFile, catsFile, groupsFile) { + let output = {}; + let counts = { + types: typesFile.length, + }; + + // setup groups + for (const key in groupsFile.groups) { + output[key] = { uuid: key, name: groupsFile.groups[key], categories: {} }; + } + + // add categories to each group + for (const key in groupsFile.category_mapping) { + output[groupsFile.category_mapping[key].group_uuid].categories[key] = { + types: [], + uuid: key, + ...groupsFile.category_mapping[key], + }; + } + + // add types to each category + // output[group uuid].categories[category uuid].types[] + // note: inefficient, needs rewrite + for (const key in output) { + typesFile.forEach((item) => { + if (output[key].categories[item.category_uuid]) { + output[key].categories[item.category_uuid].types.push(item); + } + }); + } + + return { output, counts }; +} +// example(); +module.exports = async function () { + let dataTypes = await fetchData("../pkg/classification/db/data_types/"); + let dataCats = await fetchData("../pkg/classification/db/data_categories/"); + let groupings = await fetchFile( + "../pkg/classification/db/category_grouping.json" + ); + return sortData(dataTypes, dataCats, groupings); +}; diff --git a/docs/_data/nav.js b/docs/_data/nav.js index 1fba5ca69..d110ce0c3 100644 --- a/docs/_data/nav.js +++ b/docs/_data/nav.js @@ -16,6 +16,9 @@ module.exports = [ // }, { name: "Reference", - items: [{ name: "Commands", url: "/reference/commands/" }], + items: [ + { name: "Commands", url: "/reference/commands/" }, + { name: "Data Types", url: "/reference/datatypes/" }, + ], }, ]; diff --git a/docs/_src/_includes/layouts/doc.njk b/docs/_src/_includes/layouts/doc.njk index f9f05f53c..d1984f21d 100644 --- a/docs/_src/_includes/layouts/doc.njk +++ b/docs/_src/_includes/layouts/doc.njk @@ -8,7 +8,7 @@ layout: layouts/base.njk {% for heading in nav %}
  • {{heading.name}}

    -