Skip to content

Commit 8906f9b

Browse files
authored
Include <Tldr> components content in llms.txt (#2803)
* Add new docContet.js util * Add new openLLM action * Swap generic icon for ChatGPT with the official OpenAI logo from PhosphorIcons library * Swap sparkle icon for Claude with a chat bubble icon, since sparkle is used for Kapa * Add prompt localization for the top 10 most used languages * Fix Claude incorrectly building translated prompt * Better fix Claude handling of locales by adding dual English + localized prompt * Ensure only Claude shows dual prompts * Hide descriptions for Open with… buttons * Update icon for Claude * Fix icon position when no description provided * Try to accomodate for both description and no desciption scenarii for icons placement * Revert "Try to accomodate for both description and no desciption scenarii for icons placement" This reverts commit cdb8d76. * Simplify icons alignment fix * Try to fix Claude's issue * Fix query parameter for Claude * Remove dual prompt in Claude now that we fixed the query param * Refactor translation system and add many more locales * Add aiPromptTemplates.js * Add script for translated prompt validation * Added many more languages * Include Tldr components content in llms.txt * Remove "contributing" folder * Remove "ai-toolbar-translations.md" * Remove superfluous script file
1 parent c103fcf commit 8906f9b

File tree

2 files changed

+110
-72
lines changed

2 files changed

+110
-72
lines changed

docusaurus/scripts/generate-llms.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ class DocusaurusLlmsGenerator {
118118
const { data: frontmatter, content } = matter(fileContent);
119119

120120
const pageUrl = this.generatePageUrl(docId);
121-
121+
const tldr = this.extractTldr(content);
122+
122123
pages.push({
123124
id: docId,
124125
title: frontmatter.title || this.getTitleFromContent(content) || docId,
125-
description: frontmatter.description || this.extractDescription(content),
126+
description:
127+
tldr || frontmatter.description || this.extractDescription(content),
126128
url: pageUrl,
127129
content: this.cleanContent(content),
128130
frontmatter
@@ -160,6 +162,42 @@ class DocusaurusLlmsGenerator {
160162
return '';
161163
}
162164

165+
extractTldr(content) {
166+
const match = content.match(/<Tldr>([\s\S]*?)<\/Tldr>/i);
167+
168+
if (!match) {
169+
return null;
170+
}
171+
172+
const raw = match[1].trim();
173+
174+
if (!raw) {
175+
return null;
176+
}
177+
178+
return this.sanitizeInlineMarkdown(raw);
179+
}
180+
181+
sanitizeInlineMarkdown(text) {
182+
return text
183+
// Remove fenced code blocks inside TLDR (rare but safe)
184+
.replace(/```[\s\S]*?```/g, '')
185+
// Strip inline code
186+
.replace(/`([^`]+)`/g, '$1')
187+
// Turn markdown links into plain text
188+
.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1')
189+
// Bold and italic markers
190+
.replace(/\*\*([^*]+)\*\*/g, '$1')
191+
.replace(/__([^_]+)__/g, '$1')
192+
.replace(/\*([^*]+)\*/g, '$1')
193+
.replace(/_([^_]+)_/g, '$1')
194+
// Strip residual HTML tags (including MDX components)
195+
.replace(/<[^>]+>/g, ' ')
196+
// Collapse whitespace and trim
197+
.replace(/\s+/g, ' ')
198+
.trim();
199+
}
200+
163201
cleanContent(content) {
164202
return content
165203
// Deletes frontmatter metadata

0 commit comments

Comments
 (0)