flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/docs/src/pages/[...slug].md.ts

23 lines991 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Docs in the shape of docs.continue.dev1import type { APIRoute, GetStaticPaths } from 'astro';
2import { getCollection } from 'astro:content';
3
4/**
5 * Every page as Markdown, at its path plus `.md`, for "Copy page" and for
6 * agents that read the docs: the title, what it is about, then the page.
7 */
8export const getStaticPaths: GetStaticPaths = async () => {
9 const pages = await getCollection('docs');
10 return pages.map((page) => ({
11 params: { slug: page.id === '' ? 'index' : page.id },
12 props: { page },
13 }));
14};
15
16export const GET: APIRoute = ({ props }) => {
17 const { page } = props as { page: Awaited<ReturnType<typeof getCollection<'docs'>>>[number] };
18 const { title, description } = page.data;
19 // MDX pages keep their markup; strip imports and leave the rest readable.
20 const body = (page.body ?? '').replace(/^import .*$/gm, '').trim();
21 const text = `# ${title}\n\n${description ? `> ${description}\n\n` : ''}${body}\n`;
22 return new Response(text, { headers: { 'content-type': 'text/markdown; charset=utf-8' } });
23};