1
- import { defineConfig , DefaultTheme } from "vitepress" ;
1
+ import { DefaultTheme , defineConfig } from "vitepress" ;
2
2
import path from "path" ;
3
3
import fs from "fs-extra" ;
4
4
import { fileURLToPath } from "url" ;
5
+ import { transformerTwoslash } from "@shikijs/vitepress-twoslash" ;
6
+ import ts from "typescript" ;
5
7
import typedocSidebar from "../docs/api/typedoc-sidebar.json" ; // if this import fails, run `npm run docs:generateTypedoc`
6
8
import envVar from "env-var" ;
7
9
import process from "process" ;
@@ -126,6 +128,29 @@ export default defineConfig({
126
128
{ rel : "canonical" , href : canonicalUrl }
127
129
] )
128
130
} ,
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
+ } ,
129
154
themeConfig : {
130
155
editLink : {
131
156
pattern : "https://github.com/withcatai/node-llama-cpp/edit/master/docs/:path"
@@ -196,6 +221,7 @@ export default defineConfig({
196
221
collapsed : true ,
197
222
link : "/" ,
198
223
items : [
224
+ { text : "Pull" , link : "/pull" } ,
199
225
{ text : "Chat" , link : "/chat" } ,
200
226
{ text : "Download" , link : "/download" } ,
201
227
{ text : "Complete" , link : "/complete" } ,
@@ -216,6 +242,7 @@ export default defineConfig({
216
242
} ]
217
243
} ,
218
244
socialLinks : [
245
+ { icon : "npm" , link : "https://www.npmjs.com/package/node-llama-cpp" } ,
219
246
{ icon : "github" , link : "https://github.com/withcatai/node-llama-cpp" }
220
247
]
221
248
}
@@ -257,8 +284,6 @@ function getApiReferenceSidebar(): typeof typedocSidebar {
257
284
return item ;
258
285
259
286
case "Variables" :
260
- item . text = "Enums" ;
261
-
262
287
if ( item . collapsed )
263
288
item . collapsed = false ;
264
289
@@ -271,6 +296,7 @@ function getApiReferenceSidebar(): typeof typedocSidebar {
271
296
}
272
297
273
298
function orderApiReferenceSidebar ( sidebar : typeof typedocSidebar ) : typeof typedocSidebar {
299
+ applyOverrides ( sidebar ) ;
274
300
orderClasses ( sidebar ) ;
275
301
orderTypes ( sidebar ) ;
276
302
orderFunctions ( sidebar ) ;
@@ -280,6 +306,23 @@ function orderApiReferenceSidebar(sidebar: typeof typedocSidebar): typeof typedo
280
306
return sidebar ;
281
307
}
282
308
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
+
283
326
function orderClasses ( sidebar : typeof typedocSidebar ) {
284
327
const baseChatWrapper = "ChatWrapper" ;
285
328
const chatWrapperItems : DefaultTheme . SidebarItem [ ] = [ ] ;
@@ -322,21 +365,36 @@ function orderClasses(sidebar: typeof typedocSidebar) {
322
365
{ moveToEndIfGrouped : false }
323
366
)
324
367
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
+ }
332
381
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
+ }
340
398
341
399
sortItemsInOrder ( chatWrapperItems , chatWrappersOrder ) ;
342
400
}
0 commit comments