Skip to content

Commit 00fef7b

Browse files
fix: enhance symlink error logging and image link
1 parent 04ef016 commit 00fef7b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@docusaurus/types": "3.9.2",
5959
"@types/plotly.js-basic-dist": "^1.54.4",
6060
"@types/react-plotly.js": "^2.6.3",
61-
"docusaurus-plugin-llms": "^0.2.2",
61+
"docusaurus-plugin-llms": "0.2.2",
6262
"jest": "^29.7.0",
6363
"ts-jest": "^29.1.1",
6464
"ts-node": "^10.9.2",

plugins/llms-symlinks.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ function createSymlinkAwareReader() {
4545
visited.add(realPath);
4646

4747
const files = [];
48-
const entries = await fs.readdir(dir, {withFileTypes: true});
48+
let entries;
49+
try {
50+
entries = await fs.readdir(dir, {withFileTypes: true});
51+
} catch (error) {
52+
console.warn(
53+
`Skipping unreadable directory "${dir}": ${error.message}`,
54+
);
55+
return [];
56+
}
4957

5058
for (const entry of entries) {
5159
const fullPath = path.join(dir, entry.name);
@@ -382,6 +390,14 @@ module.exports = function llmsSymlinksPlugin(context, options) {
382390
cleaned = rewritten.join('\n');
383391
}
384392

393+
// Transform remaining image links to preserve alt text context for LLMs.
394+
// ![alt text](path) -> [Image: alt text]
395+
// This removes broken relative paths while keeping semantic information.
396+
cleaned = cleaned.replace(
397+
/!\[([^\]]*)\]\([^)]+\)/g,
398+
(_match, alt) => (alt.trim() ? `[Image: ${alt.trim()}]` : ''),
399+
);
400+
385401
// Final cleanup
386402
cleaned = cleaned
387403
.replace(/\r\n/g, '\n')

0 commit comments

Comments
 (0)