|
| 1 | +import { getCollection } from 'astro:content'; |
| 2 | +import type { APIRoute } from 'astro'; |
| 3 | + |
| 4 | +function getHeaderLevel(slug: string): number { |
| 5 | + return slug.split('/').length + 1; |
| 6 | +} |
| 7 | +function groupDocsByPrefix(docs: Awaited<ReturnType<typeof getCollection<'docs'>>>) { |
| 8 | + const prefixes = ['start', 'concept', 'security', 'develop', 'distribute', 'learn', 'plugins']; |
| 9 | + |
| 10 | + const grouped = new Map<string, typeof docs>(); |
| 11 | + prefixes.forEach((prefix) => { |
| 12 | + grouped.set( |
| 13 | + prefix, |
| 14 | + docs.filter((doc) => doc.slug.startsWith(prefix)) |
| 15 | + ); |
| 16 | + }); |
| 17 | + |
| 18 | + return grouped; |
| 19 | +} |
| 20 | + |
| 21 | +const aboutBlurb = `Tauri is a framework for building tiny, fast binaries for all major desktop and mobile platforms. Developers can integrate any frontend framework that compiles to HTML, JavaScript, and CSS for building their user experience while leveraging languages such as Rust, Swift, and Kotlin for backend logic when needed.`; |
| 22 | + |
| 23 | +const organizationBlur = `This index links to documentation that covers everything from getting started to advanced concepts, and distribution of Tauri applications. |
| 24 | +
|
| 25 | +The index is organized into key sections: |
| 26 | +- **start**: Information for getting up and running with Tauri, including prerequisites and installation instructions |
| 27 | +- **core concepts**: Topics that you should get more intimately familiar with if you want to get the most out of the framework. |
| 28 | +- **security**: High-level concepts and security features at the core of Tauri’s design and ecosystem that make you, your applications and your users more secure by default |
| 29 | +- **develop**: Topics pertaining to the development of Tauri applications, including how to use the Tauri API, communicating between the frontend and backend, configuration, state management, debugging and more. |
| 30 | +- **distribute**: Information on the tooling you need to distribute your application either to the platform app stores or as platform-specific installers. |
| 31 | +- **learn**: Tutorials intended to provided end-to-end learning experiences to guide you through specific Tauri topics and help you apply knowledge from the guides and reference documentation. |
| 32 | +- **plugins**: Information on the extensibility of Tauri from Built-in Tauri features and functionality to provided plugins and recipes built by the Tauri community |
| 33 | +- **about**: Various information about Tauri from governance, philosophy, and trademark guidelines. |
| 34 | +
|
| 35 | +Each section contains links to detailed markdown files that provide comprehensive information about Tauri's features and how to use them effectively.`; |
| 36 | + |
| 37 | +export const GET: APIRoute = async ({ params, request }) => { |
| 38 | + const docs = await getCollection('docs'); |
| 39 | + const grouped = groupDocsByPrefix(docs); |
| 40 | + let content = `# Tauri app Full Documentation\n\n${aboutBlurb}\n\n${organizationBlur}\n\n**Table of Contents**\n`; |
| 41 | + for (const [prefix, items] of grouped) { |
| 42 | + if (items.length > 0) { |
| 43 | + content += `\n## ${prefix.charAt(0).toUpperCase() + prefix.slice(1)}\n`; |
| 44 | + items.forEach((doc) => { |
| 45 | + const level = getHeaderLevel(doc.slug); |
| 46 | + const indent = ' '.repeat(level - 2); |
| 47 | + content += `${indent}- [${doc.data.title}](https://tauri.app/${doc.slug}/)\n`; |
| 48 | + }); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return new Response(content, { |
| 53 | + headers: { 'Content-Type': 'text/plain; charset=utf-8' }, |
| 54 | + }); |
| 55 | +}; |
0 commit comments