Files
indiekit-endpoint-microsub/lib/feeds/jsonfeed.js
Ricardo 4819c229cd feat: restore full microsub implementation with reader UI
Restores complete implementation from feat/endpoint-microsub branch:
- Reader UI with views (reader.njk, channel.njk, feeds.njk, etc.)
- Feed polling, parsing, and normalization
- WebSub subscriber
- SSE realtime updates
- Redis caching
- Search indexing
- Media proxy
- Webmention processing
2026-02-06 20:20:25 +01:00

44 lines
1.1 KiB
JavaScript

/**
* JSON Feed parser
* @module feeds/jsonfeed
*/
import { normalizeJsonFeedItem, normalizeJsonFeedMeta } from "./normalizer.js";
/**
* Parse JSON Feed content
* @param {string} content - JSON Feed content
* @param {string} feedUrl - URL of the feed
* @returns {Promise<object>} Parsed feed with metadata and items
*/
export async function parseJsonFeed(content, feedUrl) {
let feed;
try {
feed = typeof content === "string" ? JSON.parse(content) : content;
} catch (error) {
throw new Error(`JSON Feed parse error: ${error.message}`);
}
// Validate JSON Feed structure
if (!feed.version || !feed.version.includes("jsonfeed.org")) {
throw new Error("Invalid JSON Feed: missing or invalid version");
}
if (!Array.isArray(feed.items)) {
throw new TypeError("Invalid JSON Feed: items must be an array");
}
const normalizedMeta = normalizeJsonFeedMeta(feed, feedUrl);
const normalizedItems = feed.items.map((item) =>
normalizeJsonFeedItem(item, feedUrl),
);
return {
type: "feed",
url: feedUrl,
...normalizedMeta,
items: normalizedItems,
};
}