mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-15 17:19:40 +02:00
news-ingester and apps/api both shipped their own copy of rss-parser + jsdom + Readability glue. Single source now in packages/shared-rss. Adds discoverFeeds (rel=alternate + common-paths probe) and validateFeed which News Research will use. JSDOM virtualConsole is silenced once, in the package, instead of in two parallel call sites. - packages/shared-rss: parse, extract, discover, validate - services/news-ingester: drop local parsers, depend on @mana/shared-rss - apps/api: drop @mozilla/readability + jsdom direct deps, use shared Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
24 lines
554 B
TypeScript
24 lines
554 B
TypeScript
import { parseFeedMeta } from './parse';
|
|
import type { FeedValidation } from './types';
|
|
|
|
const SAMPLE_LIMIT = 5;
|
|
|
|
export async function validateFeed(url: string): Promise<FeedValidation> {
|
|
try {
|
|
const parsed = await parseFeedMeta(url);
|
|
return {
|
|
ok: parsed.items.length > 0,
|
|
itemCount: parsed.items.length,
|
|
title: parsed.title,
|
|
sample: parsed.items.slice(0, SAMPLE_LIMIT),
|
|
};
|
|
} catch (err) {
|
|
return {
|
|
ok: false,
|
|
itemCount: 0,
|
|
title: null,
|
|
sample: [],
|
|
error: err instanceof Error ? err.message : String(err),
|
|
};
|
|
}
|
|
}
|