catalog
This plugin automatically generates catalog pages and provides catalog components.
Usage
npm i -D @vuepress/plugin-catalog@nextimport { catalogPlugin } from '@vuepress/plugin-catalog'
export default {
plugins: [
catalogPlugin({
// Your options
}),
],
}Guide
Catalog Info
First, you should set catalog info in routeMeta:
import { catalogPlugin } from '@vuepress/plugin-catalog'
export default {
extendsPage: (page) => {
// Set catalog info in routeMeta
page.routeMeta = {
// Catalog title
title: page.title,
// ... other information
}
},
}You can then import defineCatalogInfoGetter from @vuepress/plugin-catalog/client and use it in client config file to extract catalog info from route meta.
import { defineCatalogInfoGetter } from '@vuepress/plugin-catalog/client'
defineCatalogInfoGetter((meta) => (meta.title ? { title: meta.title } : null))Catalog info should contain:
title: Catalog titleorder: Catalog order (optional)content: Catalog content component (optional)
Sorting with Order
The plugin sorts pages by order in the following sequence:
// Positive numbers from small to large
Project with order 1
Project with order 2
...
Project with order 10
...
// Projects without order
Project without order
Project without order
...
// Negative numbers from small to large
Project with order -10
// ...
Project with order -2
Project with order -1Options
1 | 2 | 33Maximum depth of catalog items.
booleanWhether to show index numbers for catalog items.
(path: string, app: App) => PageFrontmatterFrontmatter getter for generated pages, where app is the VuePress app instance.
import { catalogPlugin } from '@vuepress/plugin-catalog'
export default {
plugins: [
catalogPlugin({
frontmatter: (path, app) => ({
// Frontmatter you want
// You may customize title, author, time, etc.
}),
}),
],
}(RegExp | string)[][]Catalog page path to be excluded during generation.
"/foo/"means only exclude catalog page generation at the/foo/folder./^\/foo\//means exclude catalog page generation at the/foo/folder and its subfolders.
404 pages will be automatically excluded.
stringComponent name to use as the catalog component.
By default the plugin registers and uses a <Catalog /> component.
CatalogPluginLocaleConfigLocale config of the catalog component.
See also: Locales.
stringCatalog title text.
stringEmpty hint text.
Client Options
defineCatalogInfoGetter
interface CatalogInfo {
/** Catalog title */
title: string
/** Catalog order */
order?: number
/** Catalog content */
content?: Component
}
type CatalogInfoGetter = (meta: Record<string, unknown>) => CatalogInfo | null
const defineCatalogInfoGetter: (options: CatalogInfoGetter) => voidCustomizes how to extract catalog info from route meta.
Components
Catalog
Details:
This plugin globally registers a
<Catalog />component by default (unless you set thecomponentoption).You can use
<Catalog />in theme layouts or directly in Markdown files.The component supports four props:
level: Changes the display depth (maximum 3 levels), default is3.base: Displays catalog of the specified folder, default is the current folder.index: Adds index numbers to catalog items, default is no numbers.hideHeading: Hides the component title, default is to display theCatalogtitle.
Styles
You can customize catalog styles via CSS variables:
:root {
--catalog-c-accent: var(--vp-c-accent);
--catalog-c-accent-text: var(--vp-c-accent-text);
--catalog-c-control: var(--vp-c-bg-alt);
--catalog-c-control-hover: var(--vp-c-bg-alt);
--catalog-c-divider: var(--vp-c-divider);
--catalog-header-offset: var(--header-offset, 3.6rem);
}