Add feed discovery plugin

This commit is contained in:
Anthony Ettinger 2026-06-09 09:34:31 +00:00
parent e47616bf9d
commit 5cfeea6b57
37 changed files with 2432 additions and 5 deletions

View file

@ -0,0 +1,27 @@
import { readFeedDiscoveryConfig } from "./config.js";
import { parseFeedDocument } from "./feed-parsing.js";
import { fetchTextWithGuards } from "./http.js";
import type { FeedDiscoveryConfig, ValidationResult } from "./types.js";
import { canonicalizeUrl } from "./url-safety.js";
export async function validateFeed(feedUrl: string, config: Partial<FeedDiscoveryConfig> = {}): Promise<ValidationResult> {
const resolvedConfig = { ...readFeedDiscoveryConfig(), ...config };
try {
const response = await fetchTextWithGuards(feedUrl, resolvedConfig);
const canonicalFeedUrl = canonicalizeUrl(response.url || feedUrl);
const parsed = parseFeedDocument(canonicalFeedUrl, response.body, response.contentType);
return {
...parsed,
feedUrl,
canonicalFeedUrl
};
} catch (error) {
return {
ok: false,
feedUrl,
kind: "unknown",
sampleItems: [],
error: error instanceof Error ? error.message : String(error)
};
}
}