@@ -12,11 +12,13 @@ import {rehype} from "rehype";
12
12
import sharp from "sharp" ;
13
13
import { GitChangelog , GitChangelogMarkdownSection } from "@nolebase/vitepress-plugin-git-changelog/vite" ;
14
14
import { buildEndGenerateOpenGraphImages } from "@nolebase/vitepress-plugin-og-image/vitepress" ;
15
+ import llmstxt from "vitepress-plugin-llms" ;
15
16
import { Resvg , initWasm as initResvgWasm , type ResvgRenderOptions } from "@resvg/resvg-wasm" ;
16
17
import { BlogPageInfoPlugin } from "./config/BlogPageInfoPlugin.js" ;
17
- import { getApiReferenceSidebar } from "./config/apiReferenceSidebar.js" ;
18
18
import { ensureLocalImage } from "./utils/ensureLocalImage.js" ;
19
19
import { getExcerptFromMarkdownFile } from "./utils/getExcerptFromMarkdownFile.js" ;
20
+ import { getVitepressSidebar , getVitepressSidebarWithBlog } from "./config/sidebar.js" ;
21
+ import { getBlogPosts } from "./config/getBlogPosts.js" ;
20
22
import type { Element as HastElement , Parent } from "hast" ;
21
23
22
24
import type { Node as UnistNode } from "unist" ;
@@ -365,6 +367,12 @@ export default defineConfig({
365
367
} ) as VitepressPlugin ,
366
368
BlogPageInfoPlugin ( {
367
369
include : ( id ) => id . includes ( path . sep + "blog" + path . sep ) && ! id . endsWith ( path . sep + "blog" + path . sep + "index.md" )
370
+ } ) ,
371
+ llmstxt ( {
372
+ ignoreFiles : [ "index.md" ] ,
373
+ domain : resolveHref ( "/test" ) . slice ( 0 , - "/test" . length ) || undefined ,
374
+ excludeBlog : false ,
375
+ sidebar : ( ) => getVitepressSidebarWithBlog ( true , false )
368
376
} )
369
377
] ,
370
378
build : {
@@ -434,6 +442,9 @@ export default defineConfig({
434
442
} , {
435
443
text : "GitHub Discussions" ,
436
444
link : "https://github.com/withcatai/node-llama-cpp/discussions"
445
+ } , {
446
+ text : "Awesome List" ,
447
+ link : "/guide/awesome"
437
448
} , {
438
449
text : "Contribute" ,
439
450
link : "/guide/contributing"
@@ -469,100 +480,14 @@ export default defineConfig({
469
480
}
470
481
}
471
482
} ,
472
- sidebar : {
473
- "/guide/" : [ {
474
- text : "Guide" ,
475
- base : "/guide" ,
476
- items : [
477
- { text : "Getting Started" , link : "/" } ,
478
- { text : "Chat Session" , link : "/chat-session" } ,
479
- { text : "Chat Wrapper" , link : "/chat-wrapper" } ,
480
- { text : "Grammar" , link : "/grammar" } ,
481
- { text : "Function Calling" , link : "/function-calling" } ,
482
- { text : "Embedding" , link : "/embedding" } ,
483
- { text : "Text Completion" , link : "/text-completion" } ,
484
- { text : "Choosing a Model" , link : "/choosing-a-model" } ,
485
- { text : "Downloading Models" , link : "/downloading-models" }
486
- ]
487
- } , {
488
- text : "Advanced" ,
489
- base : "/guide" ,
490
- items : [
491
- { text : "Building From Source" , link : "/building-from-source" } ,
492
- { text : "Metal Support" , link : "/Metal" } ,
493
- { text : "CUDA Support" , link : "/CUDA" } ,
494
- { text : "Vulkan Support" , link : "/Vulkan" } ,
495
- { text : "Electron Support" , link : "/electron" } ,
496
- { text : "Using in Docker" , link : "/docker" } ,
497
- { text : "Using Tokens" , link : "/tokens" } ,
498
- { text : "LlamaText" , link : "/llama-text" } ,
499
- { text : "External Chat State" , link : "/external-chat-state" } ,
500
- { text : "Token Bias" , link : "/token-bias" } ,
501
- { text : "Objects Lifecycle" , link : "/objects-lifecycle" } ,
502
- { text : "Chat Context Shift" , link : "/chat-context-shift" } ,
503
- { text : "Batching" , link : "/batching" } ,
504
- { text : "Token Prediction" , link : "/token-prediction" } ,
505
- { text : "Low Level API" , link : "/low-level-api" } ,
506
- { text : "Awesome List" , link : "/awesome" } ,
507
- { text : "Troubleshooting" , link : "/troubleshooting" } ,
508
- { text : "Tips and Tricks" , link : "/tips-and-tricks" }
509
- ]
510
- } , {
511
- text : "Contributing" ,
512
- base : "/guide" ,
513
- items : [
514
- { text : "Setting Up a Dev Environment" , link : "/development" } ,
515
- { text : "Pull Request Guidelines" , link : "/contributing" }
516
- ]
517
- } ] ,
518
-
519
- "/cli/" : [ {
520
- text : "CLI" ,
521
- base : "/cli" ,
522
- link : "/" ,
523
- items : [
524
- { text : "Init" , link : "/init" } ,
525
- { text : "Chat" , link : "/chat" } ,
526
- { text : "Pull" , link : "/pull" } ,
527
- {
528
- text : "Source" ,
529
- link : "/source" ,
530
- collapsed : true ,
531
- items : [
532
- { text : "Download" , link : "/source/download" } ,
533
- { text : "Build" , link : "/source/build" } ,
534
- { text : "Clear" , link : "/source/clear" }
535
- ]
536
- } ,
537
- { text : "Complete" , link : "/complete" } ,
538
- { text : "Infill" , link : "/infill" } ,
539
- {
540
- text : "Inspect" ,
541
- link : "/inspect" ,
542
- collapsed : true ,
543
- items : [
544
- { text : "GPU" , link : "/inspect/gpu" } ,
545
- { text : "GGUF" , link : "/inspect/gguf" } ,
546
- { text : "Measure" , link : "/inspect/measure" } ,
547
- { text : "Estimate" , link : "/inspect/estimate" }
548
- ]
549
- }
550
- ]
551
- } ] ,
552
-
553
- "/api/" : getApiReferenceSidebar ( )
554
- } ,
483
+ sidebar : getVitepressSidebar ( ) ,
555
484
socialLinks : [
556
485
{ icon : "npm" , link : "https://www.npmjs.com/package/node-llama-cpp" } ,
557
486
{ icon : "github" , link : "https://github.com/withcatai/node-llama-cpp" }
558
487
]
559
488
} ,
560
489
async buildEnd ( siteConfig ) {
561
- const blogPosts = await createContentLoader ( "blog/*.md" , {
562
- excerpt : true ,
563
- render : true
564
- } )
565
- . load ( ) ;
490
+ const blogPosts = await getBlogPosts ( false ) ;
566
491
567
492
async function loadSvgFontBuffers ( ) {
568
493
const interFontFilesDirectoryPath = path . join ( require . resolve ( "@fontsource/inter" ) , ".." , "files" ) ;
@@ -699,24 +624,7 @@ export default defineConfig({
699
624
...siteConfig . site ,
700
625
themeConfig : {
701
626
...siteConfig . site . themeConfig ,
702
- sidebar : {
703
- ...siteConfig . site . themeConfig . sidebar ,
704
- "/_blog/" : {
705
- text : "Blog" ,
706
- link : "/blog/" ,
707
- items : blogPosts
708
- . filter ( ( post ) => {
709
- const hasCoverImage = typeof post . frontmatter ?. image === "string" ||
710
- typeof post . frontmatter ?. image ?. url === "string" ;
711
-
712
- return ! hasCoverImage ;
713
- } )
714
- . map ( ( post ) => ( {
715
- text : post . frontmatter . title ,
716
- link : post . url
717
- } ) )
718
- }
719
- }
627
+ sidebar : await getVitepressSidebarWithBlog ( true , true )
720
628
}
721
629
}
722
630
} ) ;
@@ -744,22 +652,6 @@ export default defineConfig({
744
652
hub : "https://pubsubhubbub.appspot.com/"
745
653
} ) ;
746
654
747
- blogPosts . sort ( ( a , b ) => {
748
- const aDate = a . frontmatter . date
749
- ? new Date ( a . frontmatter . date )
750
- : null ;
751
- const bDate = b . frontmatter . date
752
- ? new Date ( b . frontmatter . date )
753
- : null ;
754
-
755
- if ( aDate == null )
756
- return - 1 ;
757
- if ( bDate == null )
758
- return 1 ;
759
-
760
- return bDate . getTime ( ) - aDate . getTime ( ) ;
761
- } ) ;
762
-
763
655
for ( const { url, frontmatter, html, src, excerpt : originalExcerpt } of blogPosts ) {
764
656
const ogImageElement = findElementInHtml ( html , ( element ) => (
765
657
element . tagName === "meta" && ( element . properties ?. name === "og:image" || element . properties ?. property === "og:image" )
@@ -819,12 +711,6 @@ export default defineConfig({
819
711
820
712
await addOgImages ( ) ;
821
713
822
- const indexPageIndex = blogPosts . findIndex ( ( post ) => post . url === "/blog/" ) ;
823
- if ( indexPageIndex < 0 )
824
- throw new Error ( "Blog index page not found" ) ;
825
-
826
- blogPosts . splice ( indexPageIndex , 1 ) ;
827
-
828
714
await addBlogRssFeed ( ) ;
829
715
830
716
try {
@@ -853,6 +739,11 @@ export default defineConfig({
853
739
path . join ( siteConfig . outDir , "logo.preview.avif" ) ,
854
740
24
855
741
) ;
742
+
743
+ await Promise . all ( [
744
+ fs . copy ( path . join ( siteConfig . outDir , "llms.txt" ) , path . join ( siteConfig . outDir , "llms.md" ) ) ,
745
+ fs . copy ( path . join ( siteConfig . outDir , "llms-full.txt" ) , path . join ( siteConfig . outDir , "llms-full.md" ) )
746
+ ] ) ;
856
747
}
857
748
} ) ;
858
749
0 commit comments