Skip to content

Fix: skip import/export statements in description extraction - #39

Merged
rachfop merged 1 commit into
rachfop:mainfrom
adeelehsan:fix/skip-imports-in-description-extraction
Apr 20, 2026
Merged

rachfop merged 1 commit into
rachfop:mainfrom
adeelehsan:fix/skip-imports-in-description-extraction

Conversation

@adeelehsan

Copy link
Copy Markdown
Contributor

Problem

When .mdx files start with import statements before any content paragraph, the description extraction for llms.txt picks up the import line as the page description:

- [Concepts](https://docs.vectara.com/docs/agents/agent-concepts.md): import CodePanel from '@site/src/theme/CodePanel';

Instead of:

- [Concepts](https://docs.vectara.com/docs/agents/agent-concepts.md): Agents are autonomous systems that understand natural language and use tools...

This is because excludeImports is applied to the content body after description extraction runs (line ~221), so import lines still get picked up by the fallback description logic (line ~171).

Related: #9

Fix

Added a check in the description extraction fallback (second priority) to skip paragraphs starting with import or export statements, consistent with how excludeImports handles content cleaning.

const isImportOrExport = /^(import\s|export\s)/.test(trimmedPara);
if (trimmedPara && !trimmedPara.startsWith('#') && !isImportOrExport) {

Testing

Tested against the Vectara docs Docusaurus site (389 pages, ~215 affected .mdx files with imports). Before/after:

Before After
[Concepts](...): import CodePanel from '@site/src/theme/CodePanel'; [Concepts](...): Agents are autonomous systems that understand natural language and use tools
[Built-in tools](...): import CodePanel from '@site/src/theme/CodePanel'; [Built-in tools](...): Tools provide agents with capabilities to interact with data and external

When a .mdx file starts with import statements before any content
paragraph, the description extraction for llms.txt picks up the
import line as the page description instead of actual content.

This adds a check to skip paragraphs that start with `import` or
`export` statements during description fallback extraction, matching
the existing behavior of excludeImports for content cleaning.

Fixes rachfop#9

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@rachfop

rachfop commented Apr 20, 2026

Copy link
Copy Markdown
Owner

Taking a look now. Thank you!

@rachfop
rachfop merged commit 779953b into rachfop:main Apr 20, 2026
scottamain pushed a commit to scottamain/docusaurus-plugin-llms that referenced this pull request Jul 10, 2026
Adds test coverage for the fix in rachfop#39 that skips import/export
statements during description extraction in .mdx files.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants