Skip to content

Commit 27d0c86

Browse files
committed
fix(llm): #805
1 parent f2d8820 commit 27d0c86

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

scripts/build-llm-docs.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path'
33
import { glob } from 'node:fs/promises'
44

55
const frontmatterRegex = /^\n*---(\n.+)*?\n---\n/
6+
const doubleNewLineRegex = /(\n{2})/g
67

78
const 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() {
9195
async 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

Comments
 (0)