| 11 | * Description content here. |
| 12 | */ |
| 13 | export async function parseProjects(url = "/GSOC/PROJECTS.md") { |
| 14 | const response = await fetch(url); |
| 15 | const text = await response.text(); |
| 16 | |
| 17 | // Match complete frontmatter blocks: ---\nyaml\n---\nbody |
| 18 | // Each match captures: full block with frontmatter + body until next --- or end |
| 19 | const regex = /---\n([\s\S]*?)\n---\n([\s\S]*?)(?=\n---\n|$)/g; |
| 20 | const projects = []; |
| 21 | |
| 22 | for (const match of text.matchAll(regex)) { |
| 23 | const [, yaml, body] = match; |
| 24 | // Reconstruct as valid frontmatter string for fm() |
| 25 | const fmString = `---\n${yaml}\n---\n${body}`; |
| 26 | const { attributes } = fm(fmString); |
| 27 | |
| 28 | if (attributes.title) { |
| 29 | const paragraphs = body.trim().split("\n\n").filter(Boolean); |
| 30 | projects.push({ |
| 31 | ...attributes, |
| 32 | technologies: attributes.technologies?.split(", ") || [], |
| 33 | description: paragraphs[0] || "", |
| 34 | longDescription: |
| 35 | paragraphs.slice(1).join("\n\n") || paragraphs[0] || "", |
| 36 | }); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return projects; |
| 41 | } |