@@ -12,11 +12,13 @@ import {rehype} from "rehype";
1212import sharp from "sharp" ;
1313import { GitChangelog , GitChangelogMarkdownSection } from "@nolebase/vitepress-plugin-git-changelog/vite" ;
1414import { buildEndGenerateOpenGraphImages } from "@nolebase/vitepress-plugin-og-image/vitepress" ;
15+ import llmstxt from "vitepress-plugin-llms" ;
1516import { Resvg , initWasm as initResvgWasm , type ResvgRenderOptions } from "@resvg/resvg-wasm" ;
1617import { BlogPageInfoPlugin } from "./config/BlogPageInfoPlugin.js" ;
17- import { getApiReferenceSidebar } from "./config/apiReferenceSidebar.js" ;
1818import { ensureLocalImage } from "./utils/ensureLocalImage.js" ;
1919import { getExcerptFromMarkdownFile } from "./utils/getExcerptFromMarkdownFile.js" ;
20+ import { getVitepressSidebar , getVitepressSidebarWithBlog } from "./config/sidebar.js" ;
21+ import { getBlogPosts } from "./config/getBlogPosts.js" ;
2022import type { Element as HastElement , Parent } from "hast" ;
2123
2224import type { Node as UnistNode } from "unist" ;
@@ -365,6 +367,12 @@ export default defineConfig({
365367 } ) as VitepressPlugin ,
366368 BlogPageInfoPlugin ( {
367369 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 )
368376 } )
369377 ] ,
370378 build : {
@@ -434,6 +442,9 @@ export default defineConfig({
434442 } , {
435443 text : "GitHub Discussions" ,
436444 link : "https://github.com/withcatai/node-llama-cpp/discussions"
445+ } , {
446+ text : "Awesome List" ,
447+ link : "/guide/awesome"
437448 } , {
438449 text : "Contribute" ,
439450 link : "/guide/contributing"
@@ -469,100 +480,14 @@ export default defineConfig({
469480 }
470481 }
471482 } ,
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 ( ) ,
555484 socialLinks : [
556485 { icon : "npm" , link : "https://www.npmjs.com/package/node-llama-cpp" } ,
557486 { icon : "github" , link : "https://github.com/withcatai/node-llama-cpp" }
558487 ]
559488 } ,
560489 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 ) ;
566491
567492 async function loadSvgFontBuffers ( ) {
568493 const interFontFilesDirectoryPath = path . join ( require . resolve ( "@fontsource/inter" ) , ".." , "files" ) ;
@@ -699,24 +624,7 @@ export default defineConfig({
699624 ...siteConfig . site ,
700625 themeConfig : {
701626 ...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 )
720628 }
721629 }
722630 } ) ;
@@ -744,22 +652,6 @@ export default defineConfig({
744652 hub : "https://pubsubhubbub.appspot.com/"
745653 } ) ;
746654
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-
763655 for ( const { url, frontmatter, html, src, excerpt : originalExcerpt } of blogPosts ) {
764656 const ogImageElement = findElementInHtml ( html , ( element ) => (
765657 element . tagName === "meta" && ( element . properties ?. name === "og:image" || element . properties ?. property === "og:image" )
@@ -819,12 +711,6 @@ export default defineConfig({
819711
820712 await addOgImages ( ) ;
821713
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-
828714 await addBlogRssFeed ( ) ;
829715
830716 try {
@@ -853,6 +739,11 @@ export default defineConfig({
853739 path . join ( siteConfig . outDir , "logo.preview.avif" ) ,
854740 24
855741 ) ;
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+ ] ) ;
856747 }
857748} ) ;
858749
0 commit comments