vite-plugin-vitepress-auto-nav

March 8, 2026 · View on GitHub

中文文档

Auto-generate VitePress default-theme nav and sidebar from runtime pages.

Features

  • Use top-level directories to generate nav when the user has not defined one, and lower-level directories to generate sidebar that always replaces the user config.
  • Support rewrites, dynamic routes, and i18n.
  • Support custom display names for folders and pages, with optional H1-based titles for pages.
  • Support visibility control and sorting for both folders and pages.
  • Support folder collapsed state in sidebar, matching the default theme behavior.
  • Support treating index.md as either a folder link or a standalone page.

Quick start

  1. Install
npm install -D vite-plugin-vitepress-auto-nav
  1. Add the plugin in .vitepress/config.ts
import { defineConfig } from 'vitepress'
import AutoNav from 'vite-plugin-vitepress-auto-nav'

export default defineConfig({
  vite: {
    plugins: [AutoNav()],
  },
})
  1. Configure the plugin if needed. Decide whether you also want to keep a custom themeConfig.nav. In most projects the top nav has only a few entries, so the plugin leaves room for manual nav customization.

  2. Start VitePress as usual

Configuration

Current paramTypeDefaultDescription
includestring | string[]-Plugin include rules, resolved as glob patterns relative to VitePress srcDir.
excludestring | string[]-Plugin exclude rules, resolved as glob patterns relative to VitePress srcDir.
standaloneIndexbooleanfalseControls how index.md is mounted inside a folder: false keeps it as the folder link, true keeps it as a standalone page.
overridesRecord<string, ItemMetaOptions>{}Entry override config. Keys can be filenames, folder names, or relative paths. If names collide, prefer relative paths.
frontmatterKeyPrefixstring''Adds a prefix to plugin frontmatter keys to avoid conflicts with existing site fields.
sorter(a, b, frontmatterKeyPrefix?) => numberdefaultSorterSort function for sibling nodes. The function input includes overrides.order.
preferArticleTitlebooleanfalseWhether page H1 should be preferred globally as the navigation label. Lower priority than displayName.
devAutoNavDevOptionsSee belowDevelopment options for watch debounce, content cache, and log output.
--SUMMARY.md-based generation is no longer supported.

overrides (ItemMetaOptions)

The same option names can also be used in Markdown frontmatter. If your project already uses these field names, add a prefix with frontmatterKeyPrefix, for example navDisplayName, navOrder, or navVisible.

Current paramTypeDefaultDescription
displayNamestring-Custom label for a file or folder entry. Higher priority than preferArticleTitle and the default file/folder name.
visiblebooleantrueControls whether the entry appears in navigation.
ordernumber-Sort weight passed into sorter. Smaller values come first.
preferArticleTitlebooleanfalseWhether to read the page H1 as the display label for this entry.
collapsedboolean-Default collapsed state for folder entries.

dev (AutoNavDevOptions)

Current paramTypeDefaultDescription
watchDebounceMsnumber1500File watcher debounce time in milliseconds, used to avoid recalculating too often during rapid edits.
cachebooleantrueWhether to reuse parsed content metadata cache in development.
logLevel'silent' | 'info' | 'debug''info'Development log level. Switch to debug when checking path resolution, merged output, or watch behavior.

Migrating from v3

Paste the section below into an AI model to get a fast migration.

Upgrade this project from vite-plugin-vitepress-auto-nav v3 to the latest version.

First, update the package:
- npm: `npm install -D vite-plugin-vitepress-auto-nav@latest`
- pnpm: `pnpm add -D vite-plugin-vitepress-auto-nav@latest`
- yarn: `yarn add -D vite-plugin-vitepress-auto-nav@latest`

Then migrate the config with these rules:

Rename these top-level options:
- `pattern` -> `include`
- `itemsSetting` -> `overrides`
- `frontmatterPrefix` -> `frontmatterKeyPrefix`
- `compareFn` -> `sorter`
- `useArticleTitle` -> `preferArticleTitle`

Rename these item/frontmatter fields:
- `title` -> `displayName`
- `sort` -> `order`
- `useArticleTitle` -> `preferArticleTitle`

Invert these booleans:
- `indexAsFolderLink` -> `standaloneIndex`, using `standaloneIndex = !indexAsFolderLink`
- `hide` -> `visible`, using `visible = !hide`

New options you may add if needed:
- `exclude`
- `dev.watchDebounceMs`
- `dev.cache`
- `dev.logLevel`

Important summary rule:
- If the existing config contains any `summary` option, `SUMMARY.md` workflow, or other summary-based generation logic, stop the migration at that point and explicitly report that summary-based generation is no longer supported in the latest version.

Migration rules:
1. Replace renamed keys directly.
2. Convert inverted booleans using the formulas above.
3. Keep unrelated VitePress config unchanged.

Output requirements:
- Return the migrated config code only.
- Preserve existing comments when possible.
- If summary-based config is detected, do not output migrated code. Output a short explanation that summary is no longer supported and ask for the page structure or content organization rules before continuing.

Development scripts

  • pnpm build
  • pnpm lint
  • pnpm lint:fix
  • pnpm format
  • pnpm test
  • pnpm test:unit
  • pnpm test:unit:coverage
  • pnpm test:integration
  • pnpm test:watch

License

MIT License © 2023 Xaviw