mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix: allow multiple radar rules per route (#14800)
* fix: allow multiple radar rules per route * fix: github folder * feat: add namespace to radar target * docs: fix types url
This commit is contained in:
@@ -1,45 +1,55 @@
|
||||
import { namespaces } from '../../lib/registry';
|
||||
import { Radar } from '../../lib/types';
|
||||
import { RadarItem } from '../../lib/types';
|
||||
import { parse } from 'tldts';
|
||||
import fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import toSource from 'tosource';
|
||||
|
||||
const maintainers: Record<string, string[]> = {};
|
||||
const radar: Radar = {};
|
||||
const radar: {
|
||||
[domain: string]: {
|
||||
_name: string;
|
||||
[subdomain: string]: RadarItem[] | string;
|
||||
};
|
||||
} = {};
|
||||
const docs = {};
|
||||
|
||||
for (const namespace in namespaces) {
|
||||
for (const path in namespaces[namespace].routes) {
|
||||
const realPath = `/${namespace}${path}`;
|
||||
const data = namespaces[namespace].routes[path];
|
||||
// maintainers
|
||||
if (data.maintainers) {
|
||||
maintainers[realPath] = data.maintainers;
|
||||
}
|
||||
if (data.radar && data.radar.source) {
|
||||
const parsedDomain = parse(new URL('https://' + data.radar.source[0]).hostname);
|
||||
const subdomain = parsedDomain.subdomain || '.';
|
||||
const domain = parsedDomain.domain;
|
||||
if (domain) {
|
||||
if (!radar[domain]) {
|
||||
radar[domain] = {
|
||||
_name: namespaces[namespace].name,
|
||||
};
|
||||
// radar
|
||||
if (data.radar?.length) {
|
||||
for (const radarItem of data.radar) {
|
||||
const parsedDomain = parse(new URL('https://' + radarItem.source[0]).hostname);
|
||||
const subdomain = parsedDomain.subdomain || '.';
|
||||
const domain = parsedDomain.domain;
|
||||
if (domain) {
|
||||
if (!radar[domain]) {
|
||||
radar[domain] = {
|
||||
_name: namespaces[namespace].name,
|
||||
};
|
||||
}
|
||||
if (!radar[domain][subdomain]) {
|
||||
radar[domain][subdomain] = [];
|
||||
}
|
||||
radar[domain][subdomain].push({
|
||||
title: radarItem.title || data.name,
|
||||
docs: `https://docs.rsshub.app/routes/${data.categories?.[0] || 'other'}`,
|
||||
source: radarItem.source.map((source) => {
|
||||
const sourceURL = new URL('https://' + source);
|
||||
return sourceURL.pathname + sourceURL.search + sourceURL.hash;
|
||||
}),
|
||||
target: radarItem.target ? `/${namespace}${radarItem.target}` : realPath,
|
||||
});
|
||||
}
|
||||
if (!radar[domain][subdomain]) {
|
||||
radar[domain][subdomain] = [];
|
||||
}
|
||||
radar[domain][subdomain].push({
|
||||
title: data.name,
|
||||
docs: `https://docs.rsshub.app/routes/${data.categories?.[0] || 'other'}`,
|
||||
source: data.radar.source.map((source) => {
|
||||
const sourceURL = new URL('https://' + source);
|
||||
return sourceURL.pathname + sourceURL.search + sourceURL.hash;
|
||||
}),
|
||||
target: data.radar.target || realPath,
|
||||
});
|
||||
}
|
||||
}
|
||||
// docs.json
|
||||
const categories = data.categories || namespaces[namespace].categories || ['other'];
|
||||
for (const category of categories) {
|
||||
if (!docs[category]) {
|
||||
|
||||
Reference in New Issue
Block a user