1- import { defineConfig , DefaultTheme } from "vitepress" ;
1+ import { DefaultTheme , defineConfig } from "vitepress" ;
22import path from "path" ;
33import fs from "fs-extra" ;
44import { fileURLToPath } from "url" ;
5+ import { transformerTwoslash } from "@shikijs/vitepress-twoslash" ;
6+ import ts from "typescript" ;
57import typedocSidebar from "../docs/api/typedoc-sidebar.json" ; // if this import fails, run `npm run docs:generateTypedoc`
68import envVar from "env-var" ;
79import process from "process" ;
@@ -126,6 +128,29 @@ export default defineConfig({
126128 { rel : "canonical" , href : canonicalUrl }
127129 ] )
128130 } ,
131+ markdown : {
132+ codeTransformers : [
133+ transformerTwoslash ( {
134+ // explicitTrigger: false,
135+ twoslashOptions : {
136+ compilerOptions : {
137+ ...( await fs . readJSON ( path . join ( __dirname , ".." , "tsconfig.json" ) ) ) . compilerOptions ,
138+ moduleResolution : undefined ,
139+ paths : {
140+ "node-llama-cpp" : [ path . resolve ( __dirname , ".." , "src" , "index.ts" ) ]
141+ } ,
142+ typeRoots : [
143+ path . resolve ( __dirname , ".." , "node_modules" ) ,
144+ path . resolve ( __dirname , ".." , "node_modules" , "@types" )
145+ ] ,
146+ module : ts . ModuleKind . ES2022 ,
147+ target : ts . ScriptTarget . ES2022
148+ } ,
149+ tsModule : ts
150+ }
151+ } )
152+ ]
153+ } ,
129154 themeConfig : {
130155 editLink : {
131156 pattern : "https://github.com/withcatai/node-llama-cpp/edit/master/docs/:path"
@@ -196,6 +221,7 @@ export default defineConfig({
196221 collapsed : true ,
197222 link : "/" ,
198223 items : [
224+ { text : "Pull" , link : "/pull" } ,
199225 { text : "Chat" , link : "/chat" } ,
200226 { text : "Download" , link : "/download" } ,
201227 { text : "Complete" , link : "/complete" } ,
@@ -216,6 +242,7 @@ export default defineConfig({
216242 } ]
217243 } ,
218244 socialLinks : [
245+ { icon : "npm" , link : "https://www.npmjs.com/package/node-llama-cpp" } ,
219246 { icon : "github" , link : "https://github.com/withcatai/node-llama-cpp" }
220247 ]
221248 }
@@ -257,8 +284,6 @@ function getApiReferenceSidebar(): typeof typedocSidebar {
257284 return item ;
258285
259286 case "Variables" :
260- item . text = "Enums" ;
261-
262287 if ( item . collapsed )
263288 item . collapsed = false ;
264289
@@ -271,6 +296,7 @@ function getApiReferenceSidebar(): typeof typedocSidebar {
271296}
272297
273298function orderApiReferenceSidebar ( sidebar : typeof typedocSidebar ) : typeof typedocSidebar {
299+ applyOverrides ( sidebar ) ;
274300 orderClasses ( sidebar ) ;
275301 orderTypes ( sidebar ) ;
276302 orderFunctions ( sidebar ) ;
@@ -280,6 +306,23 @@ function orderApiReferenceSidebar(sidebar: typeof typedocSidebar): typeof typedo
280306 return sidebar ;
281307}
282308
309+ function applyOverrides ( sidebar : typeof typedocSidebar ) {
310+ const functions = sidebar . find ( ( item ) => item . text === "Functions" ) ;
311+
312+ const llamaTextFunction = functions ?. items ?. find ( ( item ) => item . text === "LlamaText" ) ;
313+ if ( llamaTextFunction != null ) {
314+ delete ( llamaTextFunction as { link ?: string } ) . link ;
315+ }
316+
317+ const classes = sidebar . find ( ( item ) => item . text === "Classes" ) ;
318+ if ( classes != null && classes . items instanceof Array && ! classes . items . some ( ( item ) => item . text === "LlamaText" ) ) {
319+ classes . items . push ( {
320+ text : "LlamaText" ,
321+ link : "/api/classes/LlamaText.md"
322+ } ) ;
323+ }
324+ }
325+
283326function orderClasses ( sidebar : typeof typedocSidebar ) {
284327 const baseChatWrapper = "ChatWrapper" ;
285328 const chatWrapperItems : DefaultTheme . SidebarItem [ ] = [ ] ;
@@ -322,21 +365,36 @@ function orderClasses(sidebar: typeof typedocSidebar) {
322365 { moveToEndIfGrouped : false }
323366 )
324367
325- const LlamaTextGroup = {
326- text : "LlamaText" ,
327- collapsed : true ,
328- items : [ ]
329- } ;
330- ( classes . items as DefaultTheme . SidebarItem [ ] ) . push ( LlamaTextGroup ) ;
331- const LlamaTextGroupItemsOrder = [ "SpecialTokensText" , "SpecialToken" ] ;
368+ let LlamaTextGroup = classes . items . find ( ( item ) => item . text === "LlamaText" ) as {
369+ text : string ,
370+ collapsed ?: boolean ,
371+ items ?: [ ]
372+ } | undefined ;
373+ if ( LlamaTextGroup == null ) {
374+ LlamaTextGroup = {
375+ text : "LlamaText" ,
376+ collapsed : true ,
377+ items : [ ]
378+ } ;
379+ ( classes . items as DefaultTheme . SidebarItem [ ] ) . push ( LlamaTextGroup ) ;
380+ }
332381
333- groupItems (
334- classes . items ,
335- ( item ) => item === LlamaTextGroup ,
336- ( item ) => item . text != null && LlamaTextGroupItemsOrder . includes ( item . text ) ,
337- { moveToEndIfGrouped : false }
338- )
339- sortItemsInOrder ( LlamaTextGroup . items , LlamaTextGroupItemsOrder ) ;
382+ if ( LlamaTextGroup != null ) {
383+ LlamaTextGroup . collapsed = true ;
384+
385+ if ( LlamaTextGroup . items == null )
386+ LlamaTextGroup . items = [ ] ;
387+
388+ const LlamaTextGroupItemsOrder = [ "SpecialTokensText" , "SpecialToken" ] ;
389+
390+ groupItems (
391+ classes . items ,
392+ ( item ) => item === LlamaTextGroup ,
393+ ( item ) => item . text != null && LlamaTextGroupItemsOrder . includes ( item . text ) ,
394+ { moveToEndIfGrouped : false }
395+ )
396+ sortItemsInOrder ( LlamaTextGroup . items , LlamaTextGroupItemsOrder ) ;
397+ }
340398
341399 sortItemsInOrder ( chatWrapperItems , chatWrappersOrder ) ;
342400}
0 commit comments