* site: pull data from "icons" dir * site: display icons * site: remove redundant code * site: colour mode support * site: header * site: order imports * site: search * site: add toast when copying icon * site: styling * site: hero * fix: disable theme toggle transitions * feat: Use Yarn Workspaces * refactor: Update site deploy scripts * refactor: Remove dark mode for now * feat: Add site title * refactor: Fix warning and format * feat: Add dark mode back 👀 * feat: Escape key to reset query * Fix by aelfric * Add Github link * Fix #40 Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
33 lines
675 B
TypeScript
33 lines
675 B
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
import tags from '../../../../tags.json';
|
|
|
|
const directory = path.join(process.cwd(), "../../icons");
|
|
|
|
export function getAllNames() {
|
|
const fileNames = fs.readdirSync(directory);
|
|
|
|
return fileNames.map((fileName) => {
|
|
return fileName.replace(/\.svg$/, "");
|
|
});
|
|
}
|
|
|
|
export function getData(name) {
|
|
const fullPath = path.join(directory, `${name}.svg`);
|
|
const fileContents = fs.readFileSync(fullPath, "utf8");
|
|
|
|
return {
|
|
name,
|
|
tags: tags[name] || [],
|
|
src: fileContents,
|
|
};
|
|
}
|
|
|
|
export function getAllData() {
|
|
const names = getAllNames();
|
|
|
|
return names.map((name) => {
|
|
return getData(name);
|
|
});
|
|
}
|