Files
lucide/docs/scripts/writeCategoriesMetadata.mts
Eric Fennis 24dd855b87 feat(site): Improve search and add sorting options (#4453)
* setup icon popularity call

* Adjust sort button

* Adjust sorting

* Adds aliases

* Format code

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Add check for env variable

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Improve styling on mobile

* Remove hardcoded sort icon

* Fix build

* Format code

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-06-13 15:25:41 +02:00

38 lines
1.2 KiB
TypeScript

import fs from 'fs/promises';
import path from 'path';
const currentDir = process.cwd();
const dataDirectory = path.resolve(currentDir, '.vitepress/data');
const directory = path.join(process.cwd(), '../categories');
async function getAllCategoryFiles() {
const categoryDirectoryContents = await fs.readdir(directory);
const fileNames = categoryDirectoryContents.filter((file) => path.extname(file) === '.json');
const categoryJSONReadPromises = fileNames.map(async (fileName) => {
const name = path.basename(fileName, '.json');
const fileContent = await fs.readFile(path.join(directory, fileName), 'utf8');
const parsedFileContent = JSON.parse(fileContent);
return {
name,
title: parsedFileContent.title,
};
});
return Promise.all(categoryJSONReadPromises);
}
const categoriesFile = path.resolve(dataDirectory, `categoriesData.json`);
const categoriesData = await getAllCategoryFiles();
fs.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}`);
});