stack/docs/lib/code-examples.ts
Madison f3d0a68720
[Docs][Content] - Updates Example Pages -> Vite Vanilla JS examples (#1050)
<!--
Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md
-->

feat(docs): centralize code examples with dynamic variant tabs

This PR introduces a system for managing code examples centrally while
supporting file-based variant tabs (like html/script) within a single
code block.

## Changes

- **Extended variant system**: `PlatformCodeblock` now supports custom
variant names beyond just 'server'/'client', enabling tabs for any file
grouping (e.g., html/script pairs)
- **Vite example migration**: Moved vite-example.mdx code to
`code-examples/vite-example.ts` with html/script variants
- **LLM copy support**: The "Copy Markdown" button now expands
`PlatformCodeblock` components to inline the actual code, so LLMs
receive the full code examples instead of component references

## How it works

Code examples with variants are now displayed with filename-based tabs:
- Define examples with `variant: 'html'` and `variant: 'script'` in
`code-examples/`
- The tab labels automatically use the `filename` property
- When copying markdown for LLMs, all variants are included with their
filenames


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

* **Documentation**
* Added a Vite JavaScript example guide with grouped auth examples
(init, index, password, OTP, OAuth) and wired examples into the
getting-started navigation.
* Removed the previous multi-page example guide and replaced it with the
new Vite-focused page.
* Documentation generation now expands platform code blocks to inline
concrete examples for clearer rendered docs.

* **Refactor**
* Improved code-example variant handling to support flexible variant
names for better tabbed/code-sample organization.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-12-22 08:53:51 -06:00

34 lines
985 B
TypeScript

/**
* Centralized code examples for Stack Auth documentation
*
* Examples are stored as TypeScript files in: docs/code-examples/
*
* Structure:
* - language: Programming language (e.g., "JavaScript", "Python")
* - framework: Framework (e.g., "Next.js", "React", "Django")
* - variant: Optional "server" or "client"
* - code: The actual code (use template literals for multi-line)
* - highlightLanguage: Syntax highlighting language
* - filename: Display filename
*/
export type CodeExample = {
language: string;
framework: string;
/** Variant for tabbed code within the same platform/framework (e.g., 'server'/'client' or 'html'/'script') */
variant?: string;
code: string;
highlightLanguage: string;
filename?: string;
};
export type CodeExamplesMap = {
[documentPath: string]: {
[exampleName: string]: CodeExample[];
};
};
// Re-export functions from the code-examples index
export { getDocumentExamples, getExample } from '../code-examples';