From d70d2284b4f23bff55084199bd7865bc082779a7 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 1 Apr 2024 15:11:07 +0200 Subject: [PATCH] #787 - Support for glob patterns in the page folder paths --- CHANGELOG.md | 1 + src/commands/Folders.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 819fa0f2..86828ffb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - [#778](https://github.com/estruyf/vscode-front-matter/issues/778): Added the ability to open a file or webpage when custom scripts is completed - [#783](https://github.com/estruyf/vscode-front-matter/issues/783): Always show the custom panel view - [#785](https://github.com/estruyf/vscode-front-matter/issues/785): Adding common actions at the bottom of the content and media cards +- [#787](https://github.com/estruyf/vscode-front-matter/issues/787): Support for glob patterns in the page folder paths ### ⚡️ Optimizations diff --git a/src/commands/Folders.ts b/src/commands/Folders.ts index 4493374d..108ecde9 100644 --- a/src/commands/Folders.ts +++ b/src/commands/Folders.ts @@ -315,6 +315,26 @@ export class Folders { const contentFolders: ContentFolder[] = []; + // Check if wildcard is used + const wildcardFolders = folders.filter((f) => f.path.includes('*')); + if (wildcardFolders && wildcardFolders.length > 0) { + for (const folder of wildcardFolders) { + folders = folders.filter((f) => f.path !== folder.path); + + const folderPath = Folders.absWsFolder(folder, wsFolder); + const subFolders = glob.sync(folderPath, { ignore: '**/node_modules/**' }); + for (const subFolder of subFolders) { + const subFolderPath = parseWinPath(subFolder); + + folders.push({ + ...folder, + title: `${folder.title} (${subFolderPath.replace(wsFolder?.fsPath || '', '')})`, + path: subFolderPath + }); + } + } + } + folders.forEach((folder) => { if (!folder.title) { folder.title = basename(folder.path);