Skip to content

Commit 1524ea2

Browse files
feat(config): add maxFileSize option to skip large files
- Add maxFileSize configuration option (default: 512KB) - Skip files exceeding the size limit during markdown generation - Bump version to 1.2.0
1 parent 9ad466a commit 1524ea2

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "recursive-markdown-generator",
33
"displayName": "Recursive Markdown Generator",
44
"description": "Recursively generate markdown from files in the current directory",
5-
"version": "1.1.0",
5+
"version": "1.2.0",
66
"publisher": "getCurrentThread",
77
"author": {
88
"name": "getCurrentThread"
@@ -102,6 +102,11 @@
102102
".ignore"
103103
],
104104
"description": "Files containing ignore patterns (e.g., .gitignore)"
105+
},
106+
"recursiveMarkdownGenerator.maxFileSize": {
107+
"type": "number",
108+
"default": 512000,
109+
"description": "Maximum file size in bytes. Files larger than this will be skipped. (default: 512000 = 500KB)"
105110
}
106111
}
107112
}

src/extension.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ async function generateAndUpdateMarkdown(markdownPreviewProvider: MarkdownPrevie
5757
markdownPreviewProvider.updateContent("Generating markdown...");
5858
const config = vscode.workspace.getConfiguration("recursiveMarkdownGenerator");
5959
const ig = await createIgnoreFilter(config, workspaceFolder.uri.fsPath);
60-
const fileInfos = await collectFileInfos(workspaceFolder.uri.fsPath, ig);
60+
const maxFileSize = config.get("maxFileSize") || 512000; // 500KB in bytes
61+
const fileInfos = await collectFileInfos(workspaceFolder.uri.fsPath, ig, maxFileSize);
6162
markdownPreviewProvider.generatedMarkdown = generateMarkdownFromFileInfos(fileInfos);
6263
const htmlContent = convertFileInfosToHtml(fileInfos);
6364
markdownPreviewProvider.updateContent(htmlContent);
@@ -86,7 +87,8 @@ async function createIgnoreFilter(config: vscode.WorkspaceConfiguration, workspa
8687
return ig;
8788
}
8889

89-
async function collectFileInfos(directory: string, ig: ReturnType<typeof ignore>): Promise<FileInfo[]> {
90+
async function collectFileInfos(directory: string, ig: ReturnType<typeof ignore>, maxFileSize: number): Promise<FileInfo[]> {
91+
9092
// Use the new glob API
9193
const files = await glob("**/*", {
9294
cwd: directory,
@@ -105,6 +107,18 @@ async function collectFileInfos(directory: string, ig: ReturnType<typeof ignore>
105107
return null;
106108
}
107109

110+
// Check file size and skip if too large
111+
try {
112+
const stats = await fs.stat(filePath);
113+
if (stats.size > maxFileSize) {
114+
console.log(`Skipping large file (${stats.size} bytes > ${maxFileSize} bytes): ${normalizedPath}`);
115+
return null;
116+
}
117+
} catch (error) {
118+
console.error(`Error getting file stats ${filePath}:`, error);
119+
return null;
120+
}
121+
108122
const fileExtension = path.extname(filePath).toLowerCase();
109123

110124
// Special handling for docx files

0 commit comments

Comments
 (0)