RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
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<string | undefined> {
|
||||
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; }
|
||||
}
|
||||
Reference in New Issue
Block a user