11import { DefaultTheme , defineConfig , UserConfig } from "vitepress" ;
2- import { withSidebar , generateSidebar } from "vitepress-sidebar" ;
2+ import { generateSidebar } from "vitepress-sidebar" ;
33import { bundledLanguages , LanguageRegistration } from "shiki" ;
44import { groupIconMdPlugin , groupIconVitePlugin , localIconLoader } from "vitepress-plugin-group-icons" ;
5+ import { readFileSync } from "node:fs" ;
56
67
78const bdIcon = localIconLoader ( import . meta. url , "../docs/public/branding/logo_small.svg" ) ;
@@ -232,17 +233,6 @@ const SIDEBARS: Parameters<typeof generateSidebar>[0] = [
232233 frontmatterOrderDefaultValue : 1 ,
233234 manualSortFileNameByPriority : [ "getting-started" , "guides" ] ,
234235 } ,
235- // {
236- // documentRootPath: "docs",
237- // scanStartPath: "developers",
238- // basePath: "/developers/",
239- // resolvePath: "/developers/",
240- // useTitleFromFileHeading: true,
241- // includeRootIndexFile: true,
242- // sortFolderTo: "bottom",
243- // sortMenusByFrontmatterOrder: true,
244- // frontmatterOrderDefaultValue: 1,
245- // },
246236 {
247237 documentRootPath : "docs" ,
248238 scanStartPath : "plugins" ,
@@ -280,5 +270,42 @@ const SIDEBARS: Parameters<typeof generateSidebar>[0] = [
280270 } ,
281271] ;
282272
283- const userConfig : Partial < UserConfig > = withSidebar ( VITEPRESS_CONFIG , SIDEBARS ) ;
284- export default defineConfig ( userConfig ) ;
273+ // Read the BdApi file to get items that should be in the sidebar
274+ const bdConfig = readFileSync ( "./docs/api/BdApi.md" , "utf-8" ) ;
275+ const propertyRegex = / \n > ` s t a t i c ` \* \* ( .+ ) \* \* .+ \( ( .+ ) \. m d \) / g;
276+
277+ const properties : Record < string , string > = { } ;
278+ for ( const match of bdConfig . matchAll ( propertyRegex ) ) {
279+ const [ , name , path ] = match ;
280+
281+ if ( properties [ path ] ) properties [ path ] += `/${ name } ` ;
282+ else properties [ path ] = name ;
283+ }
284+
285+ const propertyItems = Object . entries ( properties ) . map ( ( [ path , name ] ) => ( {
286+ text : name ,
287+ link : path
288+ } ) ) ;
289+
290+ VITEPRESS_CONFIG . themeConfig ??= { } ;
291+ VITEPRESS_CONFIG . themeConfig . sidebar = {
292+ ...generateSidebar ( SIDEBARS ) ,
293+ "/api/" : {
294+ base : "/api/" ,
295+ items : [
296+ {
297+ text : "Overview" ,
298+ link : "index.md"
299+ } ,
300+ {
301+ text : "API Reference" ,
302+ items : [
303+ { text : "BdApi" , link : "BdApi" } ,
304+ ...propertyItems
305+ ]
306+ }
307+ ]
308+ }
309+ }
310+
311+ export default defineConfig ( VITEPRESS_CONFIG ) ;
0 commit comments