Breadcrumbs v2.11.1
Installation
Install @nolebase/vitepress-plugin-breadcrumbs
to your project dependencies by running the following command:
ni @nolebase/vitepress-plugin-breadcrumbs
pnpm add @nolebase/vitepress-plugin-breadcrumbs
npm install @nolebase/vitepress-plugin-breadcrumbs
yarn add @nolebase/vitepress-plugin-breadcrumbs
bun install @nolebase/vitepress-plugin-breadcrumbs
Configuration
Integrate with VitePress
In the VitePress configuration file (usually docs/.vitepress/config.ts
, the file path and extension may be different), import @nolebase/vitepress-plugin-breadcrumbs
, and put it into transformPageData
function:
If you've never seen a colored diff before
This is a markup rule for displaying diff in the user interface (UI).
Red parts usually represents the lines you are going to remove, commonly appeared with a Minus sign -, or you could simply understand it as: this line will be removed.
Green parts usually represents the lines you are going to add, commonly appeared with a Plus sign +, or you could simply understand it as: this line will be added.
To learn more about diff, you can check out this answer about the history of diffutils and Git's documentation
A TypeScript User?
You need to configure at least the following options:
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
},
"include": [
"**/.vitepress/**/*.ts",
"**/.vitepress/**/*.mts",
"**/.vitepress/**/*.vue"
],
"exclude": [
"node_modules"
]
}
And the options
module
option specifies the JavaScript/TypeScript module format, and Nolebase Integrations uses theESNext
-compatible module format by default.moduleResolution
option specifies the module resolution policy, since all Nolebase Integrations plugins follow the latest ECMAScript specifications and export declarations, if you encounter aCannot find module ... or its corresponding type declarations
error you may need to setmoduleResolution
toBundler
.
If you want more configurations, you can refer to the following example:
{
"compilerOptions": {
"jsx": "preserve",
"lib": [
"DOM",
"ESNext"
],
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true,
"strictNullChecks": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"removeComments": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true
},
"include": [
"**/.vitepress/**/*.ts",
"**/.vitepress/**/*.mts",
"**/.vitepress/**/*.vue"
],
"exclude": [
"node_modules"
]
}
import { defineConfig } from 'vitepress'
import { generateBreadcrumbsData } from '@nolebase/vitepress-plugin-breadcrumbs/vitepress'
export default defineConfig({
// Other configurations...
transformPageData(pageData, context) {
generateBreadcrumbsData(pageData, context)
},
})
Then please add the Breadcrumbs plugin package name @nolebase/vitepress-plugin-breadcrumbs
into the Vite options that required by VitePress to process this plugin:
If you've never seen a colored diff before
This is a markup rule for displaying diff in the user interface (UI).
Red parts usually represents the lines you are going to remove, commonly appeared with a Minus sign -, or you could simply understand it as: this line will be removed.
Green parts usually represents the lines you are going to add, commonly appeared with a Plus sign +, or you could simply understand it as: this line will be added.
To learn more about diff, you can check out this answer about the history of diffutils and Git's documentation
A TypeScript User?
You need to configure at least the following options:
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
},
"include": [
"**/.vitepress/**/*.ts",
"**/.vitepress/**/*.mts",
"**/.vitepress/**/*.vue"
],
"exclude": [
"node_modules"
]
}
And the options
module
option specifies the JavaScript/TypeScript module format, and Nolebase Integrations uses theESNext
-compatible module format by default.moduleResolution
option specifies the module resolution policy, since all Nolebase Integrations plugins follow the latest ECMAScript specifications and export declarations, if you encounter aCannot find module ... or its corresponding type declarations
error you may need to setmoduleResolution
toBundler
.
If you want more configurations, you can refer to the following example:
{
"compilerOptions": {
"jsx": "preserve",
"lib": [
"DOM",
"ESNext"
],
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true,
"strictNullChecks": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"removeComments": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true
},
"include": [
"**/.vitepress/**/*.ts",
"**/.vitepress/**/*.mts",
"**/.vitepress/**/*.vue"
],
"exclude": [
"node_modules"
]
}
import { defineConfig } from 'vitepress'
// https://vitepress.dev/reference/site-config
export default defineConfig({
vite: {
optimizeDeps: {
exclude: [
'@nolebase/vitepress-plugin-breadcrumbs/client'
]
},
ssr: {
noExternal: [
// If there are other packages that need to be processed by Vite, you can add them
'@nolebase/vitepress-plugin-breadcrumbs'
]
}
},
// Other configurations...
})
Add plugin into the Theme options of VitePress
In VitePress's theme configuration file (note that it's not a configuration file, it's usually located at docs/.vitepress/theme/index.ts
, file paths and extensions may be vary), import @nolebase/vitepress-plugin-breadcrumbs
package and add it to the Layout
section as a slot:
If you've never seen a colored diff before
This is a markup rule for displaying diff in the user interface (UI).
Red parts usually represents the lines you are going to remove, commonly appeared with a Minus sign -, or you could simply understand it as: this line will be removed.
Green parts usually represents the lines you are going to add, commonly appeared with a Plus sign +, or you could simply understand it as: this line will be added.
To learn more about diff, you can check out this answer about the history of diffutils and Git's documentation
A TypeScript User?
You need to configure at least the following options:
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
},
"include": [
"**/.vitepress/**/*.ts",
"**/.vitepress/**/*.mts",
"**/.vitepress/**/*.vue"
],
"exclude": [
"node_modules"
]
}
And the options
module
option specifies the JavaScript/TypeScript module format, and Nolebase Integrations uses theESNext
-compatible module format by default.moduleResolution
option specifies the module resolution policy, since all Nolebase Integrations plugins follow the latest ECMAScript specifications and export declarations, if you encounter aCannot find module ... or its corresponding type declarations
error you may need to setmoduleResolution
toBundler
.
If you want more configurations, you can refer to the following example:
{
"compilerOptions": {
"jsx": "preserve",
"lib": [
"DOM",
"ESNext"
],
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true,
"strictNullChecks": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"removeComments": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true
},
"include": [
"**/.vitepress/**/*.ts",
"**/.vitepress/**/*.mts",
"**/.vitepress/**/*.vue"
],
"exclude": [
"node_modules"
]
}
import type { Theme as ThemeConfig } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import { h } from 'vue'
import { NolebaseBreadcrumbs } from '@nolebase/vitepress-plugin-breadcrumbs/client'
export const Theme: ThemeConfig = {
extends: DefaultTheme,
Layout: () => {
return h(DefaultTheme.Layout, null, {
// Add breadcrumb above document
'doc-before': () => h(NolebaseBreadcrumbs),
})
}
}
export default Theme
Use custom breadcrumbs component
If you don't like the style or other something of default breadcrumb component, you can create your own component, this plugin will inject breadcrumb data into frontmatter
of the page, so you can use breadcrumb data like this:
<script setup lang="ts">
import { useData } from 'vitepress'
const { frontmatter } = useData()
console.log(frontmatter.breadcrumbs)
// and do something other...
</script>
<template>
<div>
<!-- ui of your own component -->
</div>
</template>
The breadcrumbs
property is an array:
type Breadcrumbs = {
title: string
link: string
}[]
If there isn't a index.md
in the directory, the link
will be an empty string ""