@@ -34,7 +34,8 @@ const packageVersion = env.get("DOCS_PACKAGE_VERSION")
3434 . default ( packageJson . version )
3535 . asString ( ) ;
3636
37- const hostname = "https://node-llama-cpp.withcat.ai/" ;
37+ const hostname = "https://node-llama-cpp.withcat.ai/"
38+ const buildDate = new Date ( ) ;
3839
3940const socialPosterLink = hostname + "social.poster.jpg" ;
4041const defaultPageTitle = "node-llama-cpp - node.js bindings for llama.cpp" ;
@@ -90,7 +91,7 @@ export default defineConfig({
9091 base : urlBase ,
9192 sitemap : {
9293 hostname,
93- transformItems ( items ) {
94+ async transformItems ( items ) {
9495 function priorityMatch ( a : { url : string } , b : { url : string } , matchers : ( ( url : string ) => boolean ) [ ] ) : number {
9596 for ( const matcher of matchers ) {
9697 const aMatch = matcher ( a . url ) ;
@@ -105,13 +106,38 @@ export default defineConfig({
105106 return 0 ;
106107 }
107108
109+ const blogPosts = await createContentLoader ( "blog/*.md" , {
110+ excerpt : true ,
111+ render : true
112+ } )
113+ . load ( ) ;
114+ const blogPostMap = new Map < string , typeof blogPosts [ number ] > ( ) ;
115+ for ( const blogPost of blogPosts ) {
116+ let url = blogPost . url ;
117+ if ( url . startsWith ( "/" ) )
118+ url = url . slice ( "/" . length ) ;
119+
120+ blogPostMap . set ( url , blogPost ) ;
121+ }
122+
108123 return items
109124 . map ( ( item ) => {
110- if ( item . url . startsWith ( "api/" ) || item . url . startsWith ( "cli/" ) ) {
125+ if ( item . url === "" || item . url === "blog/" ) {
126+ item . lastmod = new Date ( buildDate ) ;
127+ } else if ( item . url . startsWith ( "api/" ) || item . url . startsWith ( "cli/" ) ) {
111128 item = {
112129 ...item ,
113- lastmod : undefined
130+ lastmod : new Date ( buildDate )
114131 } ;
132+ } else if ( item . lastmod == null && item . url . startsWith ( "blog/" ) ) {
133+ const postDate = blogPostMap . get ( item . url ) ?. frontmatter . date ;
134+ if ( postDate != null ) {
135+ const parsedDate = new Date ( postDate ) ;
136+ if ( Number . isFinite ( parsedDate . getTime ( ) ) )
137+ item . lastmod = parsedDate ;
138+ }
139+ } else if ( item . lastmod == null ) {
140+ item . lastmod = new Date ( buildDate ) ;
115141 }
116142
117143 return item ;
0 commit comments