Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738import { fetchJson } from "#lib/fetchJson.ts";import type { Fetch } from "#lib/fetch.ts";
const BLOG_URL = "https://tangled.org/blog";const BLOG_ORIGIN = new URL(BLOG_URL).origin;const FEED_TTL = 5 * 60_000;
export interface BlogFeedItem { url: string; title: string; summary?: string; image?: string; date_published: string; tags?: string[]; authors?: { name: string; url?: string }[];}
let cached: { expires: number; items: BlogFeedItem[] } | undefined;
export const loadBlogFeed = async ( fetch: Fetch, timeout = 2500): Promise<BlogFeedItem[] | null> => { if (cached && cached.expires > Date.now()) return cached.items; const feed = await fetchJson<{ items?: BlogFeedItem[] }>( fetch, `${BLOG_URL}/feed.json`, timeout ); if (!Array.isArray(feed?.items)) return null; const items = feed.items.flatMap((item) => { const url = URL.parse(item.url); return url?.origin === BLOG_ORIGIN ? [{ ...item, url: url.href }] : []; }); cached = { expires: Date.now() + FEED_TTL, items }; return items;};