diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eee7f01..b36f6e65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ - [#645](https://github.com/estruyf/vscode-front-matter/issues/645): French localization added (thanks to [Clément Barbaza](https://github.com/cba85)) - [#649](https://github.com/estruyf/vscode-front-matter/issues/649): Parse optional variables from snippets - [#652](https://github.com/estruyf/vscode-front-matter/issues/652): Show the start/stop server buttons depending on the local terminal session +- [#654](https://github.com/estruyf/vscode-front-matter/issues/654): Added a new action to open the content in the browser ### 🐞 Fixes diff --git a/src/commands/Preview.ts b/src/commands/Preview.ts index 89b3454e..2f9e3890 100644 --- a/src/commands/Preview.ts +++ b/src/commands/Preview.ts @@ -258,10 +258,16 @@ export class Preview { if (!selectedFolder && article?.data && contentType && !contentType.previewPath) { // Try to find the folder by content type - const crntFolders = folders.filter((folder) => - folder.contentTypes?.includes((contentType as ContentType).name) + let crntFolders = folders.filter( + (folder) => + folder.contentTypes?.includes((contentType as ContentType).name) && folder.previewPath ); + // Use file path to find the folder + if (crntFolders.length > 0) { + crntFolders = crntFolders.filter((folder) => filePath?.startsWith(folder.path)); + } + if (crntFolders && crntFolders.length === 1) { selectedFolder = crntFolders[0]; } else if (crntFolders && crntFolders.length > 1) {