import type { Workspace } from "./model.ts"; import { boardKey, readCatalog } from "../storage/catalog.ts"; import { boardDocument } from "../storage/board.ts"; /** * The board that opens first in this workspace: the `pm-board:` key of a saved board, the path of a legacy Markdown board, * or undefined for All tasks. Settings → Project Management writes `defaultBoardId` and `defaultBoardPath` of the catalog. */ export async function defaultBoardPath(workspace: Workspace): Promise { const snapshot = await readCatalog(workspace); if (typeof snapshot.value.defaultBoardId !== "string") return; const board = snapshot.value.boards.find(board => board.value.id === snapshot.value.defaultBoardId); if (board) return board.archived ? undefined : boardKey(board.value.id); if (snapshot.value.deletedBoardIds?.includes(snapshot.value.defaultBoardId)) return; const path = snapshot.value.defaultBoardPath; if (typeof path !== "string" || path.startsWith(".") || path.includes("\\") || path.split("/").some(part => !part || part === "..")) return; try { const legacy = boardDocument(await workspace.read(path), path); return legacy?.id === snapshot.value.defaultBoardId && !legacy.archived ? path : undefined; } catch { return; } }