import fetch from "node-fetch"; import matter from "gray-matter"; import { marked } from "marked"; import sanitizeHtml from "sanitize-html"; import { Feed, FeedSection } from "@refinedev/devtools-shared"; import { FEED_MD_URL } from "src/constants"; const splitSections = (feed: string) => { const sections = feed.split("---section"); return sections.slice(1).map((section) => `---section${section}`); }; const contentToHtml = (content: string) => { const renderer = new marked.Renderer(); renderer.link = function (...args) { const out = marked.Renderer.prototype.link.apply(this, args); return out.replace( /^ { const parsed = matter(section.replace("---section", "---")); return { ...parsed.data, content: contentToHtml(parsed.content), } as FeedSection; }; const fetchFeed = async () => { try { const response = await fetch(FEED_MD_URL); return response.text(); } catch (_) { return ""; } }; export const getFeed = async (): Promise => { try { const rawContent = await fetchFeed(); const rawSections = splitSections(rawContent); const sections = rawSections.map(parseSection); return sections; } catch (e) { return []; } };