mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-13 13:48:26 +00:00
fix(docs): allow icon popularity prebuild without token (#4481)
Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
This commit is contained in:
@@ -35,9 +35,20 @@ interface AnalyticsResponse {
|
||||
}[];
|
||||
}
|
||||
|
||||
const writeIconPopularity = async (iconVisitCounts: Record<string, number>) => {
|
||||
const writePopularityPromises = Object.entries(iconVisitCounts).map(([iconName, count]) => {
|
||||
const location = path.resolve(iconPopularityDirectory, `${iconName}.json`);
|
||||
return fs.promises.writeFile(location, JSON.stringify({ count }, null, 2), 'utf-8');
|
||||
});
|
||||
|
||||
await Promise.all(writePopularityPromises);
|
||||
console.log('Successfully written icon popularity data for', writePopularityPromises.length, 'icons.');
|
||||
};
|
||||
|
||||
if (process.env.LUCIDE_ANALYTICS_TOKEN === undefined) {
|
||||
console.error('LUCIDE_ANALYTICS_TOKEN environment variable is not set. Please set it to fetch analytics data.');
|
||||
process.exit(1);
|
||||
console.warn('LUCIDE_ANALYTICS_TOKEN environment variable is not set. Writing default icon popularity data.');
|
||||
await writeIconPopularity(defaultIconNamePopularity);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -85,15 +96,9 @@ try {
|
||||
return acc;
|
||||
}, defaultIconNamePopularity);
|
||||
|
||||
const writePopularityPromises = Object.entries(iconVisitCounts).map(([iconName, count]) => {
|
||||
const location = path.resolve(iconPopularityDirectory, `${iconName}.json`);
|
||||
return fs.promises.writeFile(location, JSON.stringify({ count }, null, 2), 'utf-8');
|
||||
});
|
||||
|
||||
await Promise.all(writePopularityPromises);
|
||||
console.log('Successfully written icon popularity data for', writePopularityPromises.length, 'icons.');
|
||||
await writeIconPopularity(iconVisitCounts);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching analytics data:', error);
|
||||
await writeIconPopularity(defaultIconNamePopularity);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user