mirror of
https://github.com/tabler/tabler.git
synced 2026-10-12 21:27:06 +04:00
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
// https://llmstxt.org — the whole docs as one markdown file. Pages are the
|
|
// same markdown the `.md` mirrors serve, in sidebar order (home page first,
|
|
// pages missing from the sidebar tree last).
|
|
import type { APIRoute } from 'astro'
|
|
import { getCollection } from 'astro:content'
|
|
import { site } from '@shared/lib/site'
|
|
import { docsUrlFromId } from '@lib/docs-pages'
|
|
import { baseUrl, menuOrderedUrls, pageMarkdown } from '@lib/llms'
|
|
|
|
export const prerender = true
|
|
|
|
export const GET: APIRoute = async () => {
|
|
const menuRank = new Map(menuOrderedUrls().map((url, index) => [url, index]))
|
|
const rank = (url: string) => menuRank.get(url) ?? Infinity
|
|
const entries = (await getCollection('docs')).sort((a, b) => {
|
|
const [urlA, urlB] = [docsUrlFromId(a.id), docsUrlFromId(b.id)]
|
|
if (urlA === '/' || urlB === '/') return urlA === '/' ? -1 : 1
|
|
return rank(urlA) - rank(urlB) || urlA.localeCompare(urlB)
|
|
})
|
|
|
|
const base = baseUrl()
|
|
const pages = await Promise.all(entries.map((entry) => pageMarkdown(entry, `${base}${docsUrlFromId(entry.id)}`)))
|
|
|
|
const body = `# Tabler — full documentation
|
|
|
|
> ${site.description}
|
|
|
|
This is the complete documentation of ${site.docsUrl} as a single markdown file. A curated index of the same pages lives at ${site.docsUrl}/llms.txt.
|
|
|
|
---
|
|
|
|
${pages.join('\n\n---\n\n')}
|
|
`
|
|
|
|
return new Response(body, {
|
|
headers: {
|
|
'Content-Type': 'text/plain; charset=utf-8',
|
|
},
|
|
})
|
|
}
|