Starlight Plugins
Starlight plugins extend documentation sites with custom functionality through a hook-based system.
Plugin Structure
Section titled “Plugin Structure”A Starlight plugin exports a function that returns a StarlightPlugin object:
export default function myPlugin(config?: PluginConfig): StarlightPlugin { return { name: "my-plugin", hooks: { setup({ addIntegration, logger }) { // Plugin initialization }, }, };}Core Concepts
Section titled “Core Concepts”- Plugins use the
setuphook to add Astro integrations - Access to
addIntegrationallows injecting routes and updating config - Use
injectRouteto add custom pages with.astrocomponents - Routes require absolute file paths via
new URL('./route.astro', import.meta.url).pathname
Adding Routes
Section titled “Adding Routes”addIntegration({ name: "my-integration", hooks: { "astro:config:setup": ({ injectRoute }) => { injectRoute({ pattern: "custom-page", entrypoint: new URL("./route.astro", import.meta.url).pathname, prerender: true, }); }, },});Configuration
Section titled “Configuration”Register plugins in astro.config.mjs:
starlight({ plugins: [myPlugin({ option: "value" })],});