From fdb4a0892cceaa50709a8927946f7646f53d3804 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 13 Sep 2023 14:38:28 +0200 Subject: [PATCH] #638 - Hexo draft folder support --- CHANGELOG.md | 1 + src/dashboardWebView/hooks/usePages.tsx | 2 +- src/helpers/FrameworkDetector.ts | 27 +++++++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8217d89a..4879bffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### 🎨 Enhancements +- [#638](https://github.com/estruyf/vscode-front-matter/issues/638): Add Hexo support for the `_drafts` folder - [#659](https://github.com/estruyf/vscode-front-matter/issues/659): Implement a filter for the taxonomy dashboard - [#662](https://github.com/estruyf/vscode-front-matter/issues/662): Always show the `all articles` tab with the page counter - [#663](https://github.com/estruyf/vscode-front-matter/issues/663): Make card tags clickable to filter the view diff --git a/src/dashboardWebView/hooks/usePages.tsx b/src/dashboardWebView/hooks/usePages.tsx index 1de7d672..260f60d9 100644 --- a/src/dashboardWebView/hooks/usePages.tsx +++ b/src/dashboardWebView/hooks/usePages.tsx @@ -44,7 +44,7 @@ export default function usePages(pages: Page[]) { let pagesToShow: Page[] = Object.assign([], searchedPages); // Framework specific actions - if (framework?.toLowerCase() === 'jekyll') { + if (framework?.toLowerCase() === 'jekyll' || framework?.toLowerCase() === 'hexo') { pagesToShow = pagesToShow.map((page) => { // https://jekyllrb.com/docs/posts/#drafts const filePath = parseWinPath(page.fmFilePath); diff --git a/src/helpers/FrameworkDetector.ts b/src/helpers/FrameworkDetector.ts index 1e7ab105..43ace018 100644 --- a/src/helpers/FrameworkDetector.ts +++ b/src/helpers/FrameworkDetector.ts @@ -163,7 +163,7 @@ export class FrameworkDetector { if (await existsAsync(hexoConfig)) { const content = await readFileAsync(hexoConfig, 'utf8'); // Convert YAML to JSON - const config = jsyaml.safeLoad(content); + const config = jsyaml.load(content); // Check if post assets are used: https://hexo.io/docs/asset-folders.html#Post-Asset-Folder if (config.post_asset_folder) { @@ -171,6 +171,25 @@ export class FrameworkDetector { } } + const draftsPath = join(wsFolder?.fsPath || '', 'source', '_drafts'); + const postsPath = join(wsFolder?.fsPath || '', 'source', '_posts'); + + if (await existsAsync(draftsPath)) { + const folderUri = Uri.file(draftsPath); + await commands.executeCommand(COMMAND_NAME.registerFolder, { + title: 'drafts', + path: folderUri + }); + } + + if (await existsAsync(postsPath)) { + const folderUri = Uri.file(postsPath); + await commands.executeCommand(COMMAND_NAME.registerFolder, { + title: 'posts', + path: folderUri + }); + } + await Settings.update(SETTING_CONTENT_STATIC_FOLDER, assetFoler, true); } catch (e) { Logger.error( @@ -191,7 +210,7 @@ export class FrameworkDetector { if (await existsAsync(jekyllConfig)) { const content = await readFileAsync(jekyllConfig, 'utf8'); // Convert YAML to JSON - const config = jsyaml.safeLoad(content); + const config = jsyaml.load(content); if (config.collections_dir) { collectionDir = config.collections_dir; @@ -203,7 +222,7 @@ export class FrameworkDetector { if (await existsAsync(draftsPath)) { const folderUri = Uri.file(draftsPath); - commands.executeCommand(COMMAND_NAME.registerFolder, { + await commands.executeCommand(COMMAND_NAME.registerFolder, { title: 'drafts', path: folderUri }); @@ -211,7 +230,7 @@ export class FrameworkDetector { if (await existsAsync(postsPath)) { const folderUri = Uri.file(postsPath); - commands.executeCommand(COMMAND_NAME.registerFolder, { + await commands.executeCommand(COMMAND_NAME.registerFolder, { title: 'posts', path: folderUri });