diff --git a/.gitignore b/.gitignore index 7820353255..a8a38a8959 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ docs/.vitepress/data/iconNodes docs/.vitepress/data/iconMetaData.ts docs/.vitepress/data/releaseMetaData.json docs/.vitepress/data/releaseMetaData +docs/.vitepress/data/categoriesData.json docs/.vitepress/data/iconDetails docs/.vitepress/data/relatedIcons.json docs/.vercel diff --git a/docs/.vitepress/api/categories/index.get.ts b/docs/.vitepress/api/categories/index.get.ts index 0ac20a3e51..76e1f95def 100644 --- a/docs/.vitepress/api/categories/index.get.ts +++ b/docs/.vitepress/api/categories/index.get.ts @@ -1,4 +1,3 @@ -import { eventHandler, setResponseHeader } from 'h3'; import iconMetaData from '../../data/iconMetaData'; export default eventHandler((event) => { diff --git a/docs/.vitepress/api/data/index.get.ts b/docs/.vitepress/api/figma/data.ts similarity index 77% rename from docs/.vitepress/api/data/index.get.ts rename to docs/.vitepress/api/figma/data.ts index 16dc6d4efd..1c938c998a 100644 --- a/docs/.vitepress/api/data/index.get.ts +++ b/docs/.vitepress/api/figma/data.ts @@ -1,9 +1,8 @@ -import { eventHandler, setResponseHeader } from 'h3'; -import iconNodes from '../../data/iconNodes'; -import { IconNodeWithKeys } from '../../theme/types.ts'; -import iconMetaData from '../../data/iconMetaData.ts'; +import iconNodes from '../../data/iconNodes/index.ts'; +import { IconNodeWithKeys } from '../../theme/types'; +import iconMetaData from '../../data/iconMetaData'; import releaseMeta from '../../data/releaseMetaData.json'; -import { getAllCategoryFiles } from '../../lib/categories.ts'; +import categories from '../../data/categoriesData.json'; const dataResponse = { icons: Object.entries(iconNodes).reduce((acc, [name, iconNode]) => { @@ -30,7 +29,7 @@ const dataResponse = { return acc; }, {}), - categories: getAllCategoryFiles(), + categories, }; export default eventHandler((event) => { diff --git a/docs/.vitepress/api/tags/index.get.ts b/docs/.vitepress/api/tags/index.get.ts index b2314c4f45..2ffccbdc02 100644 --- a/docs/.vitepress/api/tags/index.get.ts +++ b/docs/.vitepress/api/tags/index.get.ts @@ -1,4 +1,3 @@ -import { eventHandler, setResponseHeader } from 'h3'; import iconMetaData from '../../data/iconMetaData'; export default eventHandler((event) => { diff --git a/docs/package.json b/docs/package.json index b67141d11b..feb5b81f1e 100644 --- a/docs/package.json +++ b/docs/package.json @@ -12,6 +12,7 @@ "prebuild:iconNodes": "node ../scripts/writeIconNodes.mjs", "prebuild:metaJson": "node ../scripts/writeIconMetaIndex.mjs", "prebuild:releaseJson": "node ../scripts/writeReleaseMetadata.mjs", + "prebuild:categoriesJson": "node ./scripts/writeCategoriesMetadata.mjs", "prebuild:relatedIcons": "node ../scripts/writeIconRelatedIcons.mjs", "prebuild:iconDetails": "node ../scripts/writeIconDetails.mjs", "postbuild:vercelJson": "node ../scripts/writeVercelOutput.mjs", diff --git a/docs/scripts/writeCategoriesMetadata.mjs b/docs/scripts/writeCategoriesMetadata.mjs new file mode 100644 index 0000000000..45e87cb0ca --- /dev/null +++ b/docs/scripts/writeCategoriesMetadata.mjs @@ -0,0 +1,36 @@ +import fs from 'fs'; +import path from 'path'; + +const currentDir = process.cwd(); +const dataDirectory = path.resolve(currentDir, '.vitepress/data'); +const directory = path.join(process.cwd(), '../categories'); + +function getAllCategoryFiles() { + const fileNames = fs.readdirSync(directory).filter((file) => path.extname(file) === '.json'); + + return fileNames.map((fileName) => { + const name = path.basename(fileName, '.json'); + const fileContent = fs.readFileSync(path.join(directory, fileName), 'utf8'); + + const parsedFileContent = JSON.parse(fileContent); + + return { + name, + title: parsedFileContent.title, + }; + }); +} + +const categoriesFile = path.resolve(dataDirectory, `categoriesData.json`); + +const categoriesData = getAllCategoryFiles() + +fs.promises + .writeFile(categoriesFile, JSON.stringify(categoriesData, null, 2), 'utf-8') + .then(() => { + console.log('Successfully written categoriesData.json file'); + }) + .catch((error) => { + throw new Error(`Something went wrong generating the categoriesData.json file,\n ${error}`); + }); +