| 1 | import type { MarkdownInstance } from 'astro'; |
| 2 | |
| 3 | type GuideFrontmatter = { title: string; description: string; group: string; order: number; keywords?: string }; |
| 4 | const modules = import.meta.glob<MarkdownInstance<GuideFrontmatter>>('../../../docs/guide/*.md', { eager: true }); |
| 5 | export const guidePages = Object.entries(modules).map(([path, content]) => ({ |
| 6 | slug: path.split('/').at(-1)!.replace(/\.md$/, ''), |
| 7 | ...content.frontmatter, |
| 8 | content, |
| 9 | })).sort((a, b) => a.order - b.order); |
| 10 | export const guideGroups = [...new Set(guidePages.map(page => page.group))]; |
| 11 | export const guideURL = (slug: string) => `${import.meta.env.BASE_URL}docs/${slug === 'index' ? '' : `${slug}/`}`; |
| 12 | export function guideHTML(html: string) { |
| 13 | |
| 14 | return html.replace(/(src|href)="\.\.\/\.\.\/www\/public\/([^\"]+)"/g, (_, attribute: string, asset: string) => `${attribute}="${import.meta.env.BASE_URL}${asset}"`) |
| 15 | .replaceAll('href="https://lee-xeo.github.io/Claude-Cage/', `href="${import.meta.env.BASE_URL}`).replace(/href="([^"#]+)\.md(#[^"]*)?"/g, (original, name: string, hash = '') => { |
| 16 | const page = guidePages.find(page => page.slug === name.replace(/^\.\//, '')); |
| 17 | return page ? `href="${guideURL(page.slug)}${hash}"` : original; |
| 18 | }); |
| 19 | } |