diff --git a/scripts/build-and-score-data.ts b/scripts/build-and-score-data.ts index 1c4e8a910..63e6ea901 100644 --- a/scripts/build-and-score-data.ts +++ b/scripts/build-and-score-data.ts @@ -153,22 +153,16 @@ async function buildAndScoreData() { const topicCounts: Record = missingOnly ? (topics ?? {}) : {}; data.forEach((project, index, projectList) => { - let topicSearchString = ''; + const topics = new Set(); - if (project.github.topics) { - project.github.topics.forEach(topic => { - topicSearchString = `${topicSearchString} ${topic}`; + project.github.topics?.forEach(topic => topics.add(topic)); + project.npm?.keywords?.forEach(keyword => topics.add(keyword)); - if (!topicCounts[topic]) { - topicCounts[topic] = 1; - return; - } - - topicCounts[topic] += 1; - }); + for (const topic of topics) { + topicCounts[topic] = (topicCounts[topic] ?? 0) + 1; } - projectList[index].topicSearchString = topicSearchString.trim(); + projectList[index].topicSearchString = [...topics].join(' '); }); if (invalidRepos.length) { diff --git a/scripts/fetch-npm-registry-data.ts b/scripts/fetch-npm-registry-data.ts index 44e2fd994..c66224922 100644 --- a/scripts/fetch-npm-registry-data.ts +++ b/scripts/fetch-npm-registry-data.ts @@ -2,7 +2,7 @@ import { fetch } from 'bun'; import { type LibraryType, type NpmRegistryData } from '~/types'; -import { REQUEST_SLEEP, sleep } from './helpers'; +import { processTopics, REQUEST_SLEEP, sleep } from './helpers'; const ATTEMPTS_LIMIT = 2; @@ -53,6 +53,7 @@ export async function fetchNpmRegistryData( 'deprecated' in registryData.versions[latestRelease] ? true : pkgData.unmaintained, npm: { ...pkgData.npm, + keywords: processTopics(registryData.keywords), size: registryData.versions[latestRelease].dist.unpackedSize, versionsCount: Object.keys(registryData.versions).length, latestRelease, diff --git a/types/index.ts b/types/index.ts index 7517166aa..db1a2eae4 100644 --- a/types/index.ts +++ b/types/index.ts @@ -122,6 +122,7 @@ export type LibraryType = LibraryDataEntryType & { npm?: { downloads?: number; weekDownloads?: number; + keywords?: string[]; size?: number; versionsCount?: number; latestRelease?: string;