Zum Inhalt springen

Configuring the Plugin

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

The starlight-tags plugin can be configured with the following options when added to your Starlight configuration.

astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightTags from 'starlight-tags'
export default defineConfig({
integrations: [
starlight({
plugins: [
starlightTags({
configPath: 'tags.yml',
tagsPagesPrefix: 'tags',
tagsIndexSlug: 'tags',
onInlineTagsNotFound: 'warn',
itemsPerPage: 12
}),
],
title: 'My Docs',
}),
],
})
  • Type: string
  • Default: 'tags.yml'

Path to the tags configuration file relative to your Astro project root. This file defines all available tags and their metadata.

starlightTags({
configPath: 'config/tags.yml', // Custom path
})
  • Type: string
  • Default: 'tags'

The URL prefix for individual tag pages. Each tag will be accessible at /{tagsPagesPrefix}/{tag-slug}.

starlightTags({
tagsPagesPrefix: 'topics', // Tags at /topics/javascript, /topics/react, etc.
})
  • Type: string
  • Default: 'tags'

The URL slug for the tags index page that lists all available tags.

starlightTags({
tagsIndexSlug: 'all-tags', // Index at /all-tags
})
  • Type: 'ignore' | 'warn' | 'error' | 'create'
  • Default: 'warn'

How to handle tags used in page frontmatter that are not defined in your tags configuration file.

ValueBehavior
'ignore'Silently ignore undefined tags
'warn'Log a warning during build
'error'Fail the build with an error
'create'Auto-create tags from frontmatter values
starlightTags({
onInlineTagsNotFound: 'error', // Strict mode - fail on undefined tags
})

Setting this to 'create' tells the plugin to generate tag entries on the fly for any frontmatter tags that don’t exist in tags.yml:

starlightTags({
onInlineTagsNotFound: 'create',
})

Auto-created tags only get a minimal set of properties:

  • Label: derived from the frontmatter string (hyphens and underscores become spaces)
  • Slug and URL: generated from the normalized tag ID
  • Color: inherited from defaults.color in tags.yml, if present

Properties like icon, description, difficulty, and contentType won’t be set. If you need those, define the tag explicitly in tags.yml.

  • Type: number
  • Default: 12

Number of items to display per page on individual tag pages. When a tag has more items than this limit, pagination controls will appear.

starlightTags({
itemsPerPage: 20, // Show 20 items per page
})

URL structure with pagination:

  • First page: /tags/javascript/ (clean URL)
  • Page 2: /tags/javascript/2
  • Page 3: /tags/javascript/3
  • Type: false | SidebarConfig
  • Default: false (disabled)

Automatically inject a “Popular Tags” group into Starlight’s navigation sidebar. This feature works without requiring any component overrides.

By default, sidebar injection is disabled. To enable it, provide a configuration object:

starlightTags({
sidebar: {
enabled: true, // Enable sidebar injection
position: 'top', // 'top' or 'bottom' of sidebar
limit: 10, // Number of tags to show (0 = all)
sortBy: 'count', // 'count', 'alphabetical', or 'priority'
showCount: true, // Show page count badges
collapsed: false, // Start collapsed
showViewAllLink: true // Include "View all tags" link
}
})

Sidebar configuration options (when sidebar is provided):

OptionTypeDefaultDescription
enabledbooleantrueEnable/disable sidebar injection (useful for toggling without removing config)
position'top' | 'bottom''top'Where to inject the tags group
limitnumber10Max tags to show (0 = unlimited)
sortBy'count' | 'alphabetical' | 'priority''count'Sort order for tags
showCountbooleantrueShow page count badge
collapsedbooleanfalseStart with group collapsed
showViewAllLinkbooleantrueInclude link to tags index

The sidebar group uses localized labels from the plugin’s translation system (starlightTags.popularTags and starlightTags.viewAllTags).

Here’s a complete example with all options:

astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightTags from 'starlight-tags'
export default defineConfig({
integrations: [
starlight({
plugins: [
starlightTags({
// Path to tags definition file
configPath: 'tags.yml',
// URL structure
tagsPagesPrefix: 'tags', // /tags/javascript
tagsIndexSlug: 'tags', // /tags
// Validation: 'ignore' | 'warn' | 'error' | 'create'
onInlineTagsNotFound: 'warn',
// Pagination
itemsPerPage: 12,
// Sidebar injection (optional)
sidebar: {
enabled: true,
position: 'top',
limit: 8,
sortBy: 'count',
}
}),
],
title: 'My Documentation',
}),
],
})

The plugin integrates with Starlight’s i18n system and provides:

  • Built-in UI translations for English, French, Spanish, and German
  • Localized tag labels and descriptions via object syntax in tags.yml

See the Internationalization guide for customizing translations, localizing tag content, or adding support for additional languages.