diff --git a/src/dashboardWebView/hooks/usePages.tsx b/src/dashboardWebView/hooks/usePages.tsx index 0c10078b..df822e17 100644 --- a/src/dashboardWebView/hooks/usePages.tsx +++ b/src/dashboardWebView/hooks/usePages.tsx @@ -33,8 +33,15 @@ export default function usePages(pages: Page[]) { // Framework specific actions if (framework?.toLowerCase() === "jekyll") { pagesToShow = pagesToShow.map(page => { + // https://jekyllrb.com/docs/posts/#drafts const filePath = parseWinPath(page.fmFilePath); page.draft = filePath.indexOf(`/_drafts/`) > -1; + + // Published field: https://jekyllrb.com/docs/front-matter/#predefined-global-variables + if (typeof page.published !== "undefined") { + page.draft = !page.published; + } + return page; }); } diff --git a/src/helpers/FrameworkDetector.ts b/src/helpers/FrameworkDetector.ts index 1d6c0139..862c1ca0 100644 --- a/src/helpers/FrameworkDetector.ts +++ b/src/helpers/FrameworkDetector.ts @@ -1,10 +1,12 @@ import { existsSync, readFileSync } from "fs"; +import jsyaml = require("js-yaml"); import { join, resolve } from "path"; import { commands, Uri } from "vscode"; import { Folders } from "../commands/Folders"; import { COMMAND_NAME } from "../constants"; import { FrameworkDetectors } from "../constants/FrameworkDetectors"; import { Framework } from "../models"; +import { Logger } from "./Logger"; export class FrameworkDetector { @@ -78,13 +80,32 @@ export class FrameworkDetector { return undefined; } - public static checkDefaultSettings(framework: Framework) { - const wsFolder = Folders.getWorkspaceFolder(); - + public static checkDefaultSettings(framework: Framework) { if (framework.name.toLowerCase() === "jekyll") { - const draftsPath = join(wsFolder?.fsPath || "", "_drafts"); - const postsPath = join(wsFolder?.fsPath || "", "_posts"); + FrameworkDetector.jekyll(); + } + } + + private static jekyll() { + try { + const wsFolder = Folders.getWorkspaceFolder(); + const jekyllConfig = join(wsFolder?.fsPath || "", '_config.yml'); + let collectionDir = ""; + + if (existsSync(jekyllConfig)) { + const content = readFileSync(jekyllConfig, "utf8"); + // Convert YAML to JSON + const config = jsyaml.safeLoad(content); + + if (config.collections_dir) { + collectionDir = config.collections_dir; + } + } + + const draftsPath = join(wsFolder?.fsPath || "", collectionDir, "_drafts"); + const postsPath = join(wsFolder?.fsPath || "", collectionDir, "_posts"); + if (existsSync(draftsPath)) { const folderUri = Uri.file(draftsPath); commands.executeCommand(COMMAND_NAME.registerFolder, { @@ -92,7 +113,7 @@ export class FrameworkDetector { path: folderUri }); } - + if (existsSync(postsPath)) { const folderUri = Uri.file(postsPath); commands.executeCommand(COMMAND_NAME.registerFolder, { @@ -100,6 +121,8 @@ export class FrameworkDetector { path: folderUri }); } + } catch (e) { + Logger.error(`Something failed while processing your Jekyll configuration. ${(e as Error).message}`); } } }