mirror of
https://github.com/svemagie/indiekit-endpoint-microsub.git
synced 2026-04-02 15:35:00 +02:00
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
44 lines
1.1 KiB
JavaScript
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,
|
|
};
|
|
}
|