feat(editor): Add node popularity scores to improve search ranking (#19561)

This commit is contained in:
Eugene
2025-09-17 10:25:55 +03:00
committed by GitHub
parent 69c81a6437
commit ae1af1101b
11 changed files with 332 additions and 9 deletions

View File

@@ -0,0 +1,32 @@
import { promises as fs } from 'fs';
import path from 'path';
import type { Plugin } from 'vite';
const VIRTUAL_MODULE_ID = 'virtual:node-popularity-data';
const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
export function nodePopularityPlugin(): Plugin {
return {
name: 'node-popularity-plugin',
resolveId(id) {
if (id === VIRTUAL_MODULE_ID) {
return RESOLVED_VIRTUAL_MODULE_ID;
}
},
async load(id) {
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
// Try to load the data from the build directory
const buildDataPath = path.join(process.cwd(), '.build', 'node-popularity.json');
try {
const data = await fs.readFile(buildDataPath, 'utf-8');
return `export default ${data}`;
} catch (error) {
// If file doesn't exist, return empty array
console.warn('Node popularity data not found at', buildDataPath, '- using empty array');
return 'export default []';
}
}
},
};
}