@@ -16,6 +16,7 @@ import {Resvg, initWasm as initResvgWasm, type ResvgRenderOptions} from "@resvg/
1616import { BlogPageInfoPlugin } from "./config/BlogPageInfoPlugin.js" ;
1717import { getApiReferenceSidebar } from "./config/apiReferenceSidebar.js" ;
1818import { ensureLocalImage } from "./utils/ensureLocalImage.js" ;
19+ import { getExcerptFromMarkdownFile } from "./utils/getExcerptFromMarkdownFile.js" ;
1920import type { Element as HastElement , Parent } from "hast" ;
2021
2122import type { Node as UnistNode } from "unist" ;
@@ -28,6 +29,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
2829const packageJson : typeof import ( "../package.json" ) = fs . readJsonSync ( path . join ( __dirname , ".." , "package.json" ) ) ;
2930const env = envVar . from ( process . env ) ;
3031
32+ const docsDir = path . join ( __dirname , ".." , "docs" ) ;
3133const urlBase = env . get ( "DOCS_URL_BASE" )
3234 . asString ( ) ;
3335const packageVersion = env . get ( "DOCS_PACKAGE_VERSION" )
@@ -249,6 +251,27 @@ export default defineConfig({
249251 }
250252 }
251253
254+ if ( ( description == null || description === "" ) && pageData . filePath && ! pageData . filePath . startsWith ( "api/" ) ) {
255+ const excerpt = await getExcerptFromMarkdownFile ( await fs . readFile ( path . join ( docsDir , pageData . filePath ) , "utf8" ) ) ;
256+ if ( excerpt != null && excerpt !== "" )
257+ description = excerpt . replaceAll ( '"' , "'" ) . replaceAll ( "\n" , " " ) ;
258+ }
259+
260+ pageData . description = description ;
261+
262+ if ( description != null && description !== "" &&
263+ ( pageData . frontmatter . description == null || pageData . frontmatter . description === "" )
264+ ) {
265+ pageData . frontmatter . description = description ;
266+ for ( let i = 0 ; i < head . length ; i ++ ) {
267+ const header = head [ i ] ! ;
268+ if ( header [ 0 ] === "meta" && header [ 1 ] ?. name === "description" ) {
269+ head [ i ] = [ "meta" , { name : "description" , content : description } ] ;
270+ break ;
271+ }
272+ }
273+ }
274+
252275 head . push ( [ "meta" , { name : "og:title" , content : title } ] ) ;
253276 if ( description != null && description !== "" )
254277 head . push ( [ "meta" , { name : "og:description" , content : description } ] ) ;
@@ -311,7 +334,7 @@ export default defineConfig({
311334 plugins : [
312335 GitChangelog ( {
313336 repoURL : ( ) => "https://github.com/withcatai/node-llama-cpp" ,
314- cwd : path . join ( __dirname , ".." , "docs" )
337+ cwd : docsDir
315338 } ) as VitepressPlugin ,
316339 GitChangelogMarkdownSection ( {
317340 exclude : ( id ) => (
@@ -708,7 +731,7 @@ export default defineConfig({
708731 } ) ;
709732
710733 for ( const { url, excerpt, frontmatter, html} of blogPosts ) {
711- const ogImageElement = findElementInHtml ( html , ( element ) => element . tagName === "meta" && element . properties ?. name === "og:imag " ) ;
734+ const ogImageElement = findElementInHtml ( html , ( element ) => element . tagName === "meta" && element . properties ?. name === "og:image " ) ;
712735 const date = new Date ( frontmatter . date ) ;
713736 if ( Number . isNaN ( date . getTime ( ) ) )
714737 throw new Error ( `Invalid date for blog post: ${ url } ` ) ;
0 commit comments