A comprehensive documentation site for WebGPU and TypeGPU, built with Astro Starlight. This site provides guides, tutorials, and reference material for developers working with modern GPU programming on the web.
- WebGPU Fundamentals - Core concepts, device initialization, command encoders, and error handling
- WGSL Shading Language - Syntax, data types, address spaces, and built-in functions
- TypeGPU Integration - Type-safe GPU programming with TypeScript
- Render & Compute Pipelines - Graphics rendering and general-purpose GPU computing
- Practical Tutorials - Step-by-step guides including particle systems and real-time graphics
- LLM-Optimized Content - Includes
llms.txtfor AI/LLM consumption via starlight-llms-txt
# Install dependencies
bun install
# Start development server
bun run dev
# Build for production
bun run build
# Preview production build
bun run previewsrc/
content/docs/ # Documentation pages (MDX)
lib/
pagefind-server.ts # Server-side search implementation
pages/
search.ts # Search API endpoint
This project implements server-side search using Pagefind v1.4.0+, which added Node.js runtime support. This allows search queries to be processed on the server rather than requiring client-side JavaScript.
Pagefind was originally designed for client-side browser usage. To run it on the server, we use a workaround that:
-
Loads the Pagefind module via data URL - The
pagefind.jsfile is read from disk and imported as a base64-encoded data URL to bypass ES module resolution issues. -
Mocks browser globals - Pagefind expects browser APIs, so we temporarily inject mock
window,document, andlocationobjects intoglobalThis. -
Overrides
fetchfor filesystem access - The critical piece: we replaceglobalThis.fetchwith a custom implementation that reads files from the local filesystem instead of making HTTP requests. This allows Pagefind to load its WASM binary, metadata, and index chunks fromdist/client/pagefind/. -
Normalizes result URLs - Search results are post-processed to convert absolute file paths back to relative web URLs.
src/lib/pagefind-server.ts- Core search logic with browser mocking and filesystem fetchsrc/pages/api/search.ts- Astro API route exposing the search endpoint
The search endpoint accepts POST requests:
curl -X POST http://localhost:4321/api/search \
-H "Content-Type: application/json" \
-d '{"query": "webgpu"}'Response:
{
"results": [
{
"url": "/fundamentals/webgpu-core-concepts/",
"title": "WebGPU Core Concepts",
"excerpt": "...highlighted <mark>WebGPU</mark> content...",
"score": 5.2
}
],
"totalResults": 28
}To use this approach in your own Astro/Starlight project:
- Copy
src/lib/pagefind-server.tsto your project - Create an API route that calls
searchPagefind(query, pagefindDir) - Ensure
pagefindDirpoints to your built Pagefind index (typicallydist/client/pagefind/) - The Pagefind module is initialized once and cached for subsequent requests
- Requires Pagefind v1.4.0+ for Node.js runtime detection
- The browser globals mock is minimal; complex Pagefind features may need additional mocking
- First search request incurs WASM initialization overhead (~100-200ms)
- Astro - Static site generator
- Starlight - Documentation theme
- TypeScript - Type safety
- Pagefind - Static search
- Bun - JavaScript runtime
MIT