Skip to content

Commit fdd7d4f

Browse files
committed
fix: sanitize imports and jsx
1 parent 7145f33 commit fdd7d4f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docusaurus.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,16 @@ module.exports = {
369369
ogImageURL.searchParams.set('title', result.frontMatter.title);
370370
result.frontMatter.image ??= ogImageURL.toString();
371371

372+
// Remove import statements and JSX/MDX tags from content
373+
const contentText = result.content
374+
.replace(/import\s+[^;]+;?/g, '') // Remove import statements
375+
.replace(/<[^>]+>/g, '') // Remove all tags (JSX/MDX)
376+
.replace(/\n+/g, ' ') // Replace newlines with space
377+
.replace(/\s+/g, ' ') // Collapse whitespace
378+
.trim();
372379
// Extract the first sentence (ending with . ! or ?) even if it spans multiple lines
373-
const contentText = result.content.replace(/\n+/g, ' ').replace(/\s+/g, ' ').trim();
374380
const sentenceMatch = contentText.match(/^(.*?[.!?])\s/);
375-
result.frontMatter.description = sentenceMatch ? sentenceMatch[1].trim() : contentText;
381+
result.frontMatter.description ??= sentenceMatch ? sentenceMatch[1].trim() : contentText;
376382
}
377383

378384
return result;

0 commit comments

Comments
 (0)