mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-18 14:38:24 +00:00
Site improvements (#1366)
* write cions details * add details * Add icons details * update gitignore * Add node details * Move tags api to own composable * remove overridden var * remopve whitespace * log directory existence * Fix path name * Fix build * Fix tags fetching * Move max related icons to prebuild * Improve tags scroller * Add categories call * cleanup * Add active state
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import renderIconsObject from './render/renderIconsObject.mjs';
|
||||
import { readSvgDirectory, toCamelCase } from './helpers.mjs';
|
||||
|
||||
const currentDir = process.cwd();
|
||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||
const icons = readSvgDirectory(ICONS_DIR, '.json');
|
||||
|
||||
const iconDetailsDirectory = path.resolve(currentDir, '.vitepress/data', 'iconDetails');
|
||||
|
||||
if (fs.existsSync(iconDetailsDirectory)) {
|
||||
fs.rmSync(iconDetailsDirectory, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
if (!fs.existsSync(iconDetailsDirectory)) {
|
||||
fs.mkdirSync(iconDetailsDirectory);
|
||||
}
|
||||
|
||||
const indexFile = path.resolve(iconDetailsDirectory, `index.ts`);
|
||||
|
||||
const writeIconFiles = icons.map(async (iconFileName) => {
|
||||
const iconName = path.basename(iconFileName, '.json');
|
||||
const location = path.resolve(iconDetailsDirectory, `${iconName}.ts`);
|
||||
|
||||
const contents = `\
|
||||
import iconNode from '../iconNodes/${iconName}.node.json'
|
||||
import metaData from '../../../../icons/${iconName}.json'
|
||||
import releaseData from '../releaseMetadata/${iconName}.json'
|
||||
|
||||
const { tags, categories } = metaData
|
||||
|
||||
const iconDetails = {
|
||||
name: '${iconName}',
|
||||
iconNode,
|
||||
contributors: ['ericfennis', 'karsa-mistmere'],
|
||||
tags,
|
||||
categories,
|
||||
...releaseData,
|
||||
}
|
||||
|
||||
export default iconDetails
|
||||
`;
|
||||
|
||||
await fs.promises.writeFile(location, contents, 'utf-8');
|
||||
await fs.promises.appendFile(
|
||||
indexFile,
|
||||
`export { default as ${toCamelCase(iconName)} } from './${iconName}';\n`,
|
||||
'utf-8',
|
||||
);
|
||||
});
|
||||
|
||||
Promise.all(writeIconFiles)
|
||||
.then(() => {
|
||||
console.log('Successfully write', writeIconFiles.length, 'iconDetails files.');
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(`Something went wrong generating iconNode files,\n ${error}`);
|
||||
});
|
||||
@@ -31,7 +31,9 @@ const writeIconFiles = Object.entries(icons).map(async ([iconName, { children }]
|
||||
const output = JSON.stringify(iconNode, null, 2);
|
||||
await fs.promises.writeFile(location, output, 'utf-8');
|
||||
|
||||
iconIndexFileImports.push(`import ${toCamelCase(iconName)}Node from './${iconName}.node.json';`);
|
||||
iconIndexFileImports.push(
|
||||
`import ${toCamelCase(iconName)}Node from './${iconName}.node.json' assert { type: "json" };`,
|
||||
);
|
||||
iconIndexFileExports.push(` ${toCamelCase(iconName)}Node as ${toCamelCase(iconName)},`);
|
||||
iconIndexFileDefaultExports.push(` '${iconName}': ${toCamelCase(iconName)}Node,`);
|
||||
});
|
||||
|
||||
@@ -16,6 +16,8 @@ const nameWeight = 5;
|
||||
const tagWeight = 4;
|
||||
const categoryWeight = 3;
|
||||
|
||||
const MAX_RELATED_ICONS = 4 * 17 // grid of 4x17 icons, = 68 icons
|
||||
|
||||
const arrayMatches = (a, b) => {
|
||||
// let matches = 0;
|
||||
// for (let i = 0; i < a.length; ++i) {
|
||||
@@ -44,6 +46,7 @@ const getRelatedIcons = (currentIcon, icons) => {
|
||||
.filter(a => a.similarity > 0) // @todo: maybe require a minimal non-zero similarity
|
||||
.sort((a, b) => b.similarity - a.similarity)
|
||||
.map(i => i.icon)
|
||||
.slice(0, MAX_RELATED_ICONS)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,20 @@ const currentDir = process.cwd();
|
||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||
const iconJsonFiles = readSvgDirectory(ICONS_DIR, '.json');
|
||||
const location = path.resolve(currentDir, '.vitepress/data', 'releaseMetaData.json');
|
||||
const releaseMetaDataDirectory = path.resolve(currentDir, '.vitepress/data', 'releaseMetadata');
|
||||
|
||||
if (fs.existsSync(location)) {
|
||||
fs.unlinkSync(location);
|
||||
}
|
||||
|
||||
if (fs.existsSync(releaseMetaDataDirectory)) {
|
||||
fs.rmSync(releaseMetaDataDirectory, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
if (!fs.existsSync(releaseMetaDataDirectory)) {
|
||||
fs.mkdirSync(releaseMetaDataDirectory);
|
||||
}
|
||||
|
||||
const fetchAllReleases = async () => {
|
||||
await git.fetch('https://github.com/lucide-icons/lucide.git', '--tags');
|
||||
|
||||
@@ -129,6 +138,7 @@ try {
|
||||
const releaseMetaData = await Promise.all(
|
||||
iconJsonFiles.map(async (iconJsonFile) => {
|
||||
const iconName = path.basename(iconJsonFile, '.json');
|
||||
const metaDir = path.resolve(releaseMetaDataDirectory, `${iconName}.json`);
|
||||
|
||||
if (iconName in newReleaseMetaData === false) {
|
||||
console.error(`Could not find release metadata for icon '${iconName}'.`);
|
||||
@@ -153,6 +163,9 @@ try {
|
||||
});
|
||||
}
|
||||
|
||||
const output = JSON.stringify(contents, null, 2);
|
||||
await fs.promises.writeFile(metaDir, output, 'utf-8');
|
||||
|
||||
return [iconName, contents];
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user