@@ -3,6 +3,7 @@ import path from 'node:path'
33import { glob } from 'node:fs/promises'
44
55const frontmatterRegex = / ^ \n * - - - ( \n .+ ) * ?\n - - - \n /
6+ const doubleNewLineRegex = / ( \n { 2 } ) / g
67
78const docsDir = path . resolve ( 'docs' )
89
@@ -14,7 +15,7 @@ const extractLabel = (file: string) => {
1415 return sliceExt ( file . split ( '/' ) . pop ( ) || '' )
1516}
1617
17- function capitalizeDelimiter ( str ) {
18+ function capitalizeDelimiter ( str : string ) {
1819 return str
1920 . split ( '-' )
2021 . map ( ( s ) => s . charAt ( 0 ) . toUpperCase ( ) + s . slice ( 1 ) )
@@ -64,7 +65,8 @@ async function generateLLMDocs() {
6465 const fullContent = await generateContent (
6566 files ,
6667 docsDir ,
67- '<SYSTEM>This is the full developer documentation for Hono.</SYSTEM>\n\n'
68+ '<SYSTEM>This is the full developer documentation for Hono.</SYSTEM>\n\n' ,
69+ false
6870 )
6971
7072 fs . writeFileSync ( outputFullFile , fullContent , 'utf-8' )
@@ -75,13 +77,15 @@ async function generateLLMDocs() {
7577 const tinyExclude = [ 'concepts' , 'helpers' , 'middleware' ]
7678 const tinyFiles = await glob ( '**/*.md' , {
7779 cwd : docsDir ,
78- exclude : ( filename : string ) => tinyExclude . includes ( filename ) ,
80+ exclude : ( filename : string ) =>
81+ tinyExclude . every ( ( exc ) => ! filename . includes ( exc ) ) ,
7982 } )
8083
8184 const tinyContent = await generateContent (
8285 tinyFiles ,
8386 docsDir ,
84- '<SYSTEM>This is the tiny developer documentation for Hono.</SYSTEM>\n\n'
87+ '<SYSTEM>This is the tiny developer documentation for Hono.</SYSTEM>\n\n' ,
88+ true
8589 )
8690
8791 fs . writeFileSync ( outputTinyFile , tinyContent , 'utf-8' )
@@ -91,7 +95,8 @@ async function generateLLMDocs() {
9195async function generateContent (
9296 files : NodeJS . AsyncIterator < string > ,
9397 docsDir : string ,
94- header : string
98+ header : string ,
99+ isTiny : boolean
95100) : Promise < string > {
96101 let content = header + '# Start of Hono documentation\n'
97102
@@ -101,7 +106,10 @@ async function generateContent(
101106 path . resolve ( docsDir , file ) ,
102107 'utf-8'
103108 )
104- content += fileContent . replace ( frontmatterRegex , '' ) + '\n\n'
109+ content +=
110+ fileContent
111+ . replace ( frontmatterRegex , '' )
112+ . replace ( doubleNewLineRegex , isTiny ? '\n' : '$1' ) + '\n'
105113 }
106114
107115 return content
0 commit comments