parseMarkdown.ts
1 // This function parses the markdown content into a structured format. 2 export function parseMarkdown(md: string) { 3 const items = md.split("---").map((section: string) => { 4 const lines = section.trim().split("\n"); 5 const titleMatch = lines[0]?.match(/## \[(.*?)\]\((.*?)\)/); 6 const imageUrlMatch = lines[1]?.match(/!\[logo\]\((.*?) ".*?"\)/); 7 const devices = lines[2]?.split(": ")[1]?.split(" | ").map(item => item.trim()) || []; 8 const pools = lines[3]?.split(": ")[1]?.split(" | ").map(item => item.trim()) || []; 9 const features = lines[4]?.split(": ")[1]?.split(" | ").map(item => item.trim()) || []; 10 const syncSpeed = lines[5]?.match(/!\[syncspeed\]\((.*?) ".*?"\)/); 11 12 return { 13 title: titleMatch ? titleMatch[1] : '', 14 url: titleMatch ? titleMatch[2] : '', 15 imageUrl: imageUrlMatch ? imageUrlMatch[1] : '', 16 devices, 17 pools, 18 features, 19 syncSpeed : syncSpeed ? syncSpeed[1] : '', 20 }; 21 }); 22 23 return items.filter((item) => item.title); // Filter out any empty sections 24 } 25