import type { Plugin } from 'vuepress/core' import { path } from 'vuepress/utils' import type { TocPluginOptions } from './options.js' const __dirname = import.meta.dirname /** * TOC plugin * * 目录插件 * * @example * import { tocPlugin } from '@vuepress/plugin-toc' * * export default { * plugins: [ * tocPlugin({ * componentName: 'Toc', * headersOptions: { * level: [2, 4], * }, * renderOptions: { * containerClass: 'my-toc', * linkClass: 'my-toc-link', * }, * }), * ], * } */ export const tocPlugin = ({ componentName = 'Toc', // oxlint-disable-next-line typescript/no-deprecated headerOptions = {}, // oxlint-disable-next-line typescript/no-deprecated defaultPropsOptions, // oxlint-disable-next-line typescript/no-deprecated propsOptions = {}, // oxlint-disable-next-line typescript/no-deprecated headersOptions = headerOptions, renderOptions = defaultPropsOptions ?? propsOptions, }: TocPluginOptions = {}): Plugin => ({ name: '@vuepress/plugin-toc', clientConfigFile: path.resolve(__dirname, '../client/config.js'), define: { __TOC_COMPONENT_NAME__: componentName, __TOC_HEADERS_OPTIONS__: headersOptions, __TOC_RENDER_OPTIONS__: renderOptions, }, })