Skip to content

Commit cf47681

Browse files
committed
feat: add docs/sections endpoint to list all docs sections
1 parent 5c79e0a commit cf47681

File tree

1 file changed

+21
-0
lines changed
  • apps/svelte.dev/src/routes/docs/sections

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { docs } from '$lib/server/content';
2+
import { json } from '@sveltejs/kit';
3+
4+
export const prerender = true;
5+
6+
export function GET({ url: { searchParams } }) {
7+
const complete = searchParams.has('complete');
8+
// by default we return a light version with just the title, the slug and the file path
9+
// but the user can opt in to get the complete content by adding ?complete
10+
if (complete) {
11+
return json(docs.pages);
12+
}
13+
return json(
14+
Object.fromEntries(
15+
Object.entries(docs.pages).map(([key, page]) => [
16+
key,
17+
{ metadata: { title: page.metadata.title }, slug: page.slug, file: page.file }
18+
])
19+
)
20+
);
21+
}

0 commit comments

Comments
 (0)