Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: autogenerate data type docs #183

Merged
merged 4 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions docs/_data/datatypes.js
Original file line number Diff line number Diff line change
@@ -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);
};
5 changes: 4 additions & 1 deletion docs/_data/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/" },
],
},
];
2 changes: 1 addition & 1 deletion docs/_src/_includes/layouts/doc.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ layout: layouts/base.njk
{% for heading in nav %}
<li class="mb-4">
<h2 class="font-bold text-md">{{heading.name}}</h2>
<ul class="">
<ul class="ml-2">
{% for item in heading.items %}
<li>
<a class="hover:underline" {% if currentUrl === item.url %}aria-current="page" {% endif %} href="{{item.url}}">{{item.name}}</a>
Expand Down
23 changes: 23 additions & 0 deletions docs/reference/datatypes.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Data Types
layout: layouts/doc.njk
---
{% renderTemplate "liquid,md",
datatypes %}
# Supported Data Types
Curio supports {{counts.types}} data types including Personal Data (PD), Personally Identifiable Information (PII), Protected Health Information (PHI), and Financial Data.

The following is a catagorized list of the supported data types.
{% endrenderTemplate %}

{% for key, group in datatypes.output %}
<h2 id="{{group.name}}">{{group.name}}</h2>
{% for key, cat in group.categories %}
<h3 id="{{cat.name}}">{{cat.name}}</h3>
<ul>
{% for item in cat.types %}
<li>{{item.name}}</li>
{% endfor %}
</ul>
{% endfor %}
{% endfor %}