Astro Documentation Source

repository·main·Indexed 23 days ago

https://github.com/withastro/docs

The source code and content for the official Astro documentation site (docs.astro.build). This repository includes the site configuration logic, custom Astro integrations, remark and rehype plugins, and comprehensive i18n guides and glossaries for translating documentation into languages such as Portuguese (PT-BR), Korean, and Japanese.

Tokens
299.9K
Snippets
909
Records
1.3K
Agent score
81%

What's inside withastro/docs

  1. Overview of the Astro Content Loader API

    main

    Astro's Content Loader API enables you to load data from any source—whether local or remote—and integrate it into Astro's content layer. This allows you to manage external data using the same workflows and features as content collections.

    The API provides:

    • Ready-to-use loaders: Built-in loaders for local content.
    • Custom loader tools: APIs to build your own loaders that can fetch data from any source and inject it into content collections.
  2. Introduction to Astro Actions

    main

    Astro Actions are type-safe server functions that allow you to define backend logic that can be called from anywhere (client-side components, <script> tags, or HTML forms). They provide built-in support for:

    • Input Validation: Automatically validates JSON and form data using Zod.
    • Type Safety: Generates type-safe functions for calling your backend, eliminating the need for manual fetch() calls.
    • Standardized Errors: Uses the ActionError object to provide consistent error handling with status codes.
  3. Overview of Content Collections APIs

    main

    Astro provides two types of content collections to manage and render content:

    1. Build-time content collections: Used to configure, query, and render local files (Markdown, MDX, Markdoc, YAML, TOML, or JSON) as well as remote content during the build process.
    2. Live content collections: Used to configure, query, and render fresh, real-time data from remote sources.
  4. Overview of the Astro Actions API

    main
    Astro Actions allow you to build a type-safe backend that can be invoked from both client-side JavaScript and standard HTML forms. The astro:actions module provides all the necessary utilities to define, call, and handle errors for these actions. This feature ensures that the data sent to and received from your server-side logic is type-safe across the network boundary.
  5. Explore built-in Dev toolbar apps

    main

    The Dev toolbar includes several built-in applications:

    • Astro Menu: Provides project information and links to Astro documentation, GitHub, and Discord. It includes a "Copy debug info" button that runs astro info and copies the output to your clipboard.
    • Inspect: Displays information about islands on the current page, including their properties and the client directive used to render them.
    • Audit: Automatically runs performance and accessibility audits. A red dot appears in the toolbar when issues are found. Clicking the app shows results and highlights the related elements on the page.
    • Settings: Allows you to configure toolbar options like verbose logging, disabling notifications, and adjusting screen placement.
  6. Understand the Astro project structure

    main

    Astro uses an opinionated folder layout, though most directories are conventions rather than strict requirements. The core organization revolves around src/ for processed source code and public/ for unprocessed assets.

    Core Directories

    • src/: Contains your project source code (components, pages, layouts, styles, images, etc.). Files here are processed, optimized, and bundled by Astro.
    • public/: Contains non-code, unprocessed assets (fonts, icons, robots.txt, etc.). Files here are copied to the build folder untouched and are not optimized or bundled.

    Core Files

    • package.json: Project manifest for managing dependencies and scripts (e.g., npm run dev).
    • astro.config.mjs: The Astro configuration file used to specify integrations, build options, and server settings.
    • tsconfig.json: TypeScript configuration file (recommended for editor support and type checking).
  7. Understand the structure of the `config/` directory

    main

    The config/ directory contains the logic used to configure the documentation site via astro.config.ts. It is organized into several functional areas:

    • integrations/: Contains custom Astro integrations specifically designed for the docs site.
    • plugins/: Contains plugins for remark (Markdown processing), rehype (HTML processing), or Starlight (the documentation framework).
    • Utilities: Miscellaneous helper functions and utilities to simplify the site configuration process.
  8. Supported file types for imports in Astro

    main

    Astro supports importing most static assets with zero configuration using the ESM import statement. This works in Astro frontmatter, JavaScript, and TypeScript files. @import is also supported within CSS and <style> tags.

    Out-of-the-box supported types:

    • Astro Components (.astro)
    • Markdown (.md, .markdown, etc.)
    • JavaScript (.js, .mjs)
    • TypeScript (.ts)
    • NPM Packages
    • JSON (.json)
    • CSS (.css)
    • CSS Modules (.module.css)
    • Images & Assets (.svg, .jpg, .png, etc.)

    Extensible support:

    • UI Frameworks: React, Svelte, and Vue via integrations.
    • MDX/Markdoc: .mdx or .mdoc files via the Astro MDX or Astro Markdoc integrations.
  9. What is a renderer and how to build one

    main

    A renderer is a special type of Astro integration that enables support for new component syntaxes (like UI framework components) that Astro does not handle natively.

    A renderer consists of two parts:

    1. A server module: Imported during development and production builds to render components to HTML.
    2. An optional client module: Imported in the browser to hydrate components using client directives.

    To add a renderer, create an integration and call addRenderer() within the astro:config:setup hook.

    export default function createIntegration() {
      return {
        name: "@example/my-renderer",
        hooks: {
          "astro:config:setup": ({ addRenderer }) => {
            addRenderer({
              name: "@example/my-renderer",
              clientEntrypoint: "@example/my-renderer/client.js",
              serverEntrypoint: "@example/my-renderer/server.js",
            });
          },
        },
      };
    }
  10. What is Islands Architecture in Astro

    main

    Astro uses Islands Architecture to keep websites fast by rendering the majority of a page as static HTML and only adding small, isolated "islands" of JavaScript where interactivity or personalization is required.

    This approach, also known as partial or selective hydration, avoids the heavy monolithic JavaScript payloads typical of Single-Page Applications (SPAs). In Astro, islands run in isolation from one another, allowing you to mix multiple UI frameworks (like React, Svelte, or Vue) on a single page without them interfering with each other.

  11. What is an Astro adapter?

    main

    An adapter is a specialized type of integration that enables on-demand rendering (Server-Side Rendering/SSR) for specific cloud providers. It performs two primary roles:

    1. Handles host-specific APIs: Implements the logic required to process incoming requests for a specific environment.
    2. Configures the build: Adjusts the Astro build process to comply with the target host's conventions.
  12. What is the Astro Docs MCP Server?

    main

    The Astro Docs MCP (Model Context Protocol) server provides AI tools with real-time access to the latest Astro documentation. This helps prevent AI models from using outdated information and ensures they follow current best practices. The server is free, open-source, and runs remotely via HTTP, meaning no local installation is required.

    Server Details

    • Name: Astro Docs
    • URL: https://mcp.docs.astro.build/mcp
    • Transport: Streamable HTTP