@@ -393,11 +393,13 @@ function determinePagesToSummarize(
393393) : {
394394 pagesToSummarize : PageMetadata [ ] ;
395395 pagesToKeep : Array < PageMetadata & { title : string ; description : string } > ;
396+ hasChanges : boolean ;
396397} {
397398 const pagesToSummarize : PageMetadata [ ] = [ ] ;
398399 const pagesToKeep : Array <
399400 PageMetadata & { title : string ; description : string }
400401 > = [ ] ;
402+ let hasChanges = false ;
401403
402404 if ( previousMetadata && previousMetadata . gitSha !== "unknown" ) {
403405 // Get changed files since last generation
@@ -417,6 +419,7 @@ function determinePagesToSummarize(
417419 ) ;
418420
419421 if ( deletedPageUrls . length > 0 ) {
422+ hasChanges = true ;
420423 console . log (
421424 pc . yellow (
422425 `\n🗑️ Found ${ deletedPageUrls . length } deleted pages (will be removed from output)`
@@ -435,6 +438,7 @@ function determinePagesToSummarize(
435438 if ( isChanged || ! existingSummary ) {
436439 // Need to summarize this page
437440 pagesToSummarize . push ( page ) ;
441+ hasChanges = true ;
438442 } else {
439443 // Keep existing summary
440444 pagesToKeep . push ( {
@@ -456,9 +460,10 @@ function determinePagesToSummarize(
456460 pc . yellow ( "⚠ No previous generation found, summarizing all pages" )
457461 ) ;
458462 pagesToSummarize . push ( ...pages ) ;
463+ hasChanges = true ; // Always regenerate if no previous metadata
459464 }
460465
461- return { pagesToSummarize, pagesToKeep } ;
466+ return { pagesToSummarize, pagesToKeep, hasChanges } ;
462467}
463468
464469/**
@@ -537,11 +542,8 @@ async function main() {
537542 const pages = await discoverPages ( ) ;
538543
539544 // Step 2: Determine which pages need summarization and identify deleted pages
540- const { pagesToSummarize, pagesToKeep } = determinePagesToSummarize (
541- pages ,
542- previousMetadata ,
543- existingSummaries
544- ) ;
545+ const { pagesToSummarize, pagesToKeep, hasChanges } =
546+ determinePagesToSummarize ( pages , previousMetadata , existingSummaries ) ;
545547
546548 // Step 3: Summarize changed/new pages using OpenAI
547549 const summarizedPages = await summarizePagesInBatches (
@@ -556,16 +558,29 @@ async function main() {
556558
557559 // Step 5: Generate llms.txt content
558560 console . log ( pc . blue ( "\n✍️ Generating llms.txt content..." ) ) ;
559- const generationDate = new Date ( ) . toISOString ( ) ;
560- const metadata : LlmsTxtMetadata = {
561- gitSha : currentSha ,
562- generationDate,
563- } ;
561+ // Only update metadata if there are changes, otherwise keep previous metadata
562+ const metadata : LlmsTxtMetadata = hasChanges
563+ ? {
564+ gitSha : currentSha ,
565+ generationDate : new Date ( ) . toISOString ( ) ,
566+ }
567+ : previousMetadata || {
568+ gitSha : currentSha ,
569+ generationDate : new Date ( ) . toISOString ( ) ,
570+ } ;
564571 const content = generateLlmsTxt ( sections , metadata ) ;
565572
566573 // Step 6: Write to file
567574 await fs . writeFile ( OUTPUT_PATH , content , "utf-8" ) ;
568- console . log ( pc . green ( `✓ Generated llms.txt at ${ OUTPUT_PATH } ` ) ) ;
575+ if ( hasChanges ) {
576+ console . log ( pc . green ( `✓ Generated llms.txt at ${ OUTPUT_PATH } ` ) ) ;
577+ } else {
578+ console . log (
579+ pc . gray (
580+ "✓ No changes detected, llms.txt unchanged (SHA and date preserved)"
581+ )
582+ ) ;
583+ }
569584
570585 console . log ( pc . bold ( pc . green ( "\n✨ Done!\n" ) ) ) ;
571586 } catch ( error ) {
0 commit comments