Skip to content

Commit d8ecf2c

Browse files
raifdmuellerclaude
andcommitted
fix: Address CodeRabbit review comments on generate-llms-txt
- Add try/catch for categories.json loading with clear error message - Add existsSync check before reading about.adoc - Expand decodeHtmlEntities named entity map (rsquo, ldquo, rdquo, mdash, ndash, nbsp, hellip) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3a9fd9d commit d8ecf2c

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

scripts/extract-metadata.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@ if (!fs.existsSync(OUTPUT_DIR)) {
2626
*/
2727
function decodeHtmlEntities(str) {
2828
if (!str) return str
29-
const named = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" }
29+
const named = {
30+
amp: '&',
31+
lt: '<',
32+
gt: '>',
33+
quot: '"',
34+
apos: "'",
35+
rsquo: '\u2019',
36+
lsquo: '\u2018',
37+
rdquo: '\u201d',
38+
ldquo: '\u201c',
39+
mdash: '\u2014',
40+
ndash: '\u2013',
41+
nbsp: '\u00a0',
42+
hellip: '\u2026',
43+
}
3044
return str.replace(/&#(\d+);|&([a-z]+);/gi, (match, num, name) => {
3145
if (num) return String.fromCharCode(parseInt(num, 10))
3246
return named[name] || match

scripts/generate-llms-txt.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ const path = require('path')
1313

1414
const ROOT = path.join(__dirname, '..')
1515

16-
const categories = JSON.parse(
17-
fs.readFileSync(path.join(ROOT, 'website/public/data/categories.json'), 'utf-8')
18-
)
16+
const categoriesPath = path.join(ROOT, 'website/public/data/categories.json')
17+
let categories
18+
try {
19+
categories = JSON.parse(fs.readFileSync(categoriesPath, 'utf-8'))
20+
} catch (err) {
21+
console.error('❌ Fehler beim Laden von categories.json:', err.message)
22+
console.error(' Bitte zuerst `node scripts/extract-metadata.js` ausführen.')
23+
process.exit(1)
24+
}
1925

2026
// ─── AsciiDoc table converter ────────────────────────────────────────────────
2127

@@ -199,11 +205,13 @@ function generateLlmsTxt() {
199205
]
200206

201207
// Introductory content from about.adoc
202-
const aboutAdoc = fs.readFileSync(path.join(ROOT, 'docs/about.adoc'), 'utf-8')
203-
lines.push(adocToMarkdown(aboutAdoc))
204-
lines.push('')
205-
lines.push('---')
206-
lines.push('')
208+
const aboutPath = path.join(ROOT, 'docs/about.adoc')
209+
if (fs.existsSync(aboutPath)) {
210+
lines.push(adocToMarkdown(fs.readFileSync(aboutPath, 'utf-8')))
211+
lines.push('')
212+
lines.push('---')
213+
lines.push('')
214+
}
207215

208216
// Anchors by category
209217
for (const category of categories) {

0 commit comments

Comments
 (0)