UNPKG

vitepress-sidebar

Version:

A VitePress auto sidebar plugin that automatically creates a simple configuration.

1 lines 552 B
import{join as r,sep as t}from"path";import{utimesSync as e}from"fs";export function createSidebarHmrPlugin(n){const o=(n?Array.isArray(n)?n:[n]:[{}]).map(t=>{let e=t.documentRootPath??"/";return e.startsWith("/")||(e=`/${e}`),r(process.cwd(),e)});return{name:"vitepress-sidebar:hmr",apply:"serve",configureServer(r){const n=r=>{r.endsWith(".md")&&(r=>o.some(e=>r===e||r.startsWith(e+t)))(r)&&(()=>{const r=globalThis.VITEPRESS_CONFIG?.configPath;if(!r)return;const t=new Date;try{e(r,t,t)}catch{}})()};r.watcher.on("add",n),r.watcher.on("unlink",n)}}}