File size: 5,907 Bytes
bf48b89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | import fs from 'node:fs';
import path from 'node:path';
import { config } from '../../lib/config';
import { namespaces } from '../../lib/registry';
import { getCurrentPath } from '../../lib/utils/helpers';
import { categories } from './data';
const fullTests = await (await fetch('https://cdn.jsdelivr.net/gh/DIYgod/RSSHub@gh-pages/build/test-full-routes.json')).json();
const testResult = fullTests.testResults[0].assertionResults;
const foloAnalysis = await (
await fetch('https://raw.githubusercontent.com/RSSNext/rsshub-docs/refs/heads/main/rsshub-analytics.json', {
headers: {
'user-agent': config.trueUA,
},
})
).json();
const foloAnalysisResult = foloAnalysis.data as Record<string, { subscriptionCount: number; topFeeds: any[] }>;
const foloAnalysisTop100 = Object.entries(foloAnalysisResult)
.sort((a, b) => b[1].subscriptionCount - a[1].subscriptionCount)
.slice(0, 150);
const __dirname = getCurrentPath(import.meta.url);
// Build namespace-centric data structure
interface NamespaceData {
name: string;
url?: string;
description?: string;
zh?: {
name?: string;
description?: string;
};
categories: string[];
heat: number;
routes: Record<string, RouteData>;
}
interface RouteData {
path: string | string[];
name: string;
url?: string;
maintainers: string[];
example: string;
parameters?: Record<string, any>;
description?: string;
categories?: string[];
features?: Record<string, any>;
radar?: any[];
view?: number;
location?: string;
heat: number;
topFeeds: any[];
zh?: {
name?: string;
description?: string;
parameters?: Record<string, any>;
};
test?: {
code: number;
message?: string;
};
}
const namespacesData: Record<string, NamespaceData> = {};
// First pass: build namespace data with all routes
for (const namespace in namespaces) {
const nsData = namespaces[namespace];
// Determine default category
let defaultCategory = nsData.categories?.[0];
if (!defaultCategory) {
for (const routePath in nsData.routes) {
if (nsData.routes[routePath].categories) {
defaultCategory = nsData.routes[routePath].categories[0];
break;
}
}
}
if (!defaultCategory) {
defaultCategory = 'other';
}
// Collect all categories for this namespace
const nsCategories = new Set<string>(nsData.categories || []);
// Initialize namespace data
namespacesData[namespace] = {
name: nsData.name === 'Unknown' ? namespace : nsData.name,
url: nsData.url,
description: nsData.description,
zh: nsData.zh
? {
name: nsData.zh.name,
description: nsData.zh.description,
}
: undefined,
categories: [],
heat: 0,
routes: {},
};
// Process routes
const processedPaths = new Set<string>();
for (const routePath in nsData.routes) {
const realPath = `/${namespace}${routePath}`;
const routeData = nsData.routes[routePath];
// Skip duplicate array paths
if (Array.isArray(routeData.path)) {
if (processedPaths.has(routeData.path[0])) {
continue;
}
processedPaths.add(routeData.path[0]);
}
// Determine route categories
const routeCategories = routeData.categories || nsData.categories || [defaultCategory];
// Check if popular
const isPopular = foloAnalysisTop100.some(([p]) => p === realPath);
if (isPopular && !routeCategories.includes('popular')) {
routeCategories.push('popular');
}
// Add categories to namespace
for (const cat of routeCategories) {
nsCategories.add(cat);
}
// Get test result
const test = testResult.find((t) => t.title === realPath);
const parsedTest = test
? {
code: test.status === 'passed' ? 0 : 1,
message: test.failureMessages?.[0],
}
: undefined;
const heat = foloAnalysisResult[realPath]?.subscriptionCount || 0;
// Build route data
namespacesData[namespace].routes[realPath] = {
path: routeData.path,
name: routeData.name,
url: routeData.url,
maintainers: routeData.maintainers,
example: routeData.example,
parameters: routeData.parameters,
description: routeData.description,
categories: routeCategories,
features: routeData.features,
radar: routeData.radar,
view: routeData.view,
location: routeData.location,
heat,
topFeeds: foloAnalysisResult[realPath]?.topFeeds || [],
zh: routeData.zh
? {
name: routeData.zh.name,
description: routeData.zh.description,
parameters: routeData.zh.parameters,
}
: undefined,
test: parsedTest,
};
namespacesData[namespace].heat += heat;
}
namespacesData[namespace].categories = [...nsCategories];
}
// Generate JSON output
fs.mkdirSync(path.join(__dirname, '../../assets/build/docs'), { recursive: true });
fs.writeFileSync(path.join(__dirname, '../../assets/build/docs/routes.json'), JSON.stringify(namespacesData, null, 2));
// Generate categories data
const categoriesData = categories.map((cat) => ({
id: cat.link.replace('/routes/', ''),
icon: cat.icon,
en: cat.en,
zh: cat.zh,
}));
fs.writeFileSync(path.join(__dirname, '../../assets/build/docs/categories.json'), JSON.stringify(categoriesData, null, 2));
|