UNPKG

vitepress-plugin-sidebar-permalink

Version:
110 lines (104 loc) 3.08 kB
import { Plugin } from 'vitepress'; import * as vite from 'vite'; interface SidebarItem { text: string; link?: string; items?: SidebarItem[]; collapsed?: boolean; activeMatch?: string; } interface Frontmatter { private?: boolean; permalink?: string; } interface RewritesJson { rewrites: Record<string, string>; } interface IgnoreDirs { rewriteIgnores: string[]; sidebarIgnores: string[]; } interface SidebarPermalinkOptions { /** * 根目录, 默认为 'docs' */ root?: string; /** * Markdown文章目录路径,默认为 'docs/articles' */ dir?: string; /** * 重写规则文件路径,默认为 'docs/rewrites.json' */ rewritesPath?: string; /** * 直接提供的重写规则,一般为rewritesJson.rewrites,rewritesJson为生成的json文件 * */ rewrites?: Record<string, string>; /** * sidebar配置,是否折叠 */ options?: { collapsed: boolean; }; /** * 导航栏 */ navLinks?: { text: string; link?: string; items?: any[]; }[] | null | undefined; /** * 忽略的侧边栏目录列表 * 侧边栏默认值为 [".vitepress", "node_modules", "public", "dist", "@pages", "index.md"] * */ ignoreDirs?: IgnoreDirs; } /** * 从 md 文件中读取一级标题 * @param markdownContent md 文件内容 */ declare const getTitleFromMd: (mdContent: string) => string | undefined; /** * 判断是否非法的序号 * * @param index 序号 */ declare const isIllegalIndex: (index: number) => boolean; /** * 判断数组中是否存在某个元素,支持正则表达式 * * @param arr 数组 * @param name 元素 */ declare const isSome: (arr: Array<string | RegExp>, name: string) => boolean; /** * 判断链接是否为外部链接 * @param link 链接 * @returns 如果是外部链接返回 true,否则返回 false * @description 外部链接的定义: * 1. 以 http:// 或 https:// 开头的链接 * 2. 以 mailto: 或 tel: 开头的链接 * 3. 不以 /pages 或 / 开头的链接 * 4. 如果链接为空,则视为外部链接 */ declare function isExternalLink(link?: string): boolean; /** * * @param dir 目录路径 * @description 获取指定目录下所有的 md 文件路径 * @param baseDir 基础目录,用于计算相对路径 * @param ignoreDirs 忽略目录 * @returns 返回所有 md 文件的相对路径数组 */ declare function getAllMdFiles(dir: string, baseDir?: string, ignoreDirs?: string[]): string[]; declare const logger: vite.Logger; declare let generatedSidebar: Record<string, any>; declare let generatedRewrites: Record<string, string>; declare function SidebarPermalinkPlugin(options?: SidebarPermalinkOptions): Plugin; // @ts-ignore export default SidebarPermalinkPlugin; export { generatedRewrites, generatedSidebar, getAllMdFiles, getTitleFromMd, isExternalLink, isIllegalIndex, isSome, logger }; export type { Frontmatter, IgnoreDirs, RewritesJson, SidebarItem, SidebarPermalinkOptions };