A note-taking app inspired by nb
fork

Configure Feed

Select the types of activity you want to include in your feed.

continue moving logic into classes

bitquabit.com 78e33709 564e6b55

verified
+53 -16
+26 -1
hsh.ts
··· 2 2 import type { Config } from "./config.ts"; 3 3 import { getEntryPath, getNotebookRoot } from "./paths.ts"; 4 4 import type { EventHandler } from "./plugins/plugins.ts"; 5 - import { NamedNotebookPath, Notebook } from "./notebook.ts"; 5 + import { NamedNotebookPath, Notebook, NotebookPath } from "./notebook.ts"; 6 6 import { join } from "@std/path/join"; 7 7 import { initRepo } from "./git.ts"; 8 8 ··· 22 22 for (const handler of this._handlers) { 23 23 await handler.handleNotebookChanged?.(notebook, message); 24 24 } 25 + } 26 + 27 + parse(path: string): NotebookPath { 28 + let notebook: Notebook; 29 + 30 + if (path.includes(":")) { 31 + let name: string; 32 + [name, path] = path.split(":", 2); 33 + if (!path) path = ""; 34 + notebook = this.getNotebook(name); 35 + } else { 36 + notebook = this.currentNotebook(); 37 + } 38 + 39 + let folders; 40 + let entry: string | undefined; 41 + const components = path.split("/").filter((e) => e != ""); 42 + if (path.endsWith("/")) { 43 + folders = components; 44 + } else { 45 + entry = components.pop(); 46 + folders = components; 47 + } 48 + 49 + return { notebook, folders, entry }; 25 50 } 26 51 27 52 // FIXME(bmps): This should leave this class once the whole Notebook/NotebookPath
+18 -6
notebook.ts
··· 26 26 entry?: string; 27 27 } 28 28 29 + export class NotebookPath { 30 + notebook: Notebook; 31 + folders: string[]; 32 + entry?: string; 33 + 34 + constructor(notebook: Notebook, folders: string[], entry?: string) { 35 + this.notebook = notebook; 36 + this.folders = folders; 37 + this.entry = entry; 38 + } 39 + 40 + toString(): string { 41 + return `${this.folders.join("/")}${this.folders.length > 0 ? "/" : ""}${ 42 + this.entry ?? "" 43 + }}`; 44 + } 45 + } 46 + 29 47 export interface RelativePath { 30 48 folders: string[]; 31 49 entry?: string; ··· 61 79 62 80 return { notebook, folders, entry }; 63 81 } 64 - 65 - export function unparse(path: NamedNotebookPath): string { 66 - return `${path.folders.join("/")}${path.folders.length > 0 ? "/" : ""}${ 67 - path.entry ?? "" 68 - }}`; 69 - }
+9 -9
plugins/todo.ts
··· 7 7 import { print } from "../utils.ts"; 8 8 import { relativeNotePath } from "../paths.ts"; 9 9 import { Hsh } from "../hsh.ts"; 10 - import { NamedNotebookPath, Notebook, unparse } from "../notebook.ts"; 10 + import { NamedNotebookPath, Notebook, NotebookPath } from "../notebook.ts"; 11 11 12 - async function showTodos(notebooks: Notebook[], status?: TodoStatus) { 12 + async function showTodos(hsh: Hsh, notebooks: Notebook[], status?: TodoStatus) { 13 13 const todos = await listTodos(notebooks, status); 14 14 for ( 15 15 const items of Object.values( 16 16 Object.groupBy( 17 17 todos, 18 18 (t) => 19 - unparse({ 20 - notebook: t.entry.notebook, 21 - folders: t.entry.folders, 22 - entry: t.entry.filename, 23 - }), 19 + (new NotebookPath( 20 + hsh.getNotebook(t.entry.notebook), 21 + t.entry.folders, 22 + t.entry.filename, 23 + )).toString(), 24 24 ), 25 25 ) 26 26 ) { ··· 92 92 function getTodoCommands(hsh: Hsh) { 93 93 return new Command() 94 94 .description("list and harvest todos") 95 - .action(async () => await showTodos([hsh.currentNotebook()], "open")) 95 + .action(async () => await showTodos(hsh, [hsh.currentNotebook()], "open")) 96 96 .command("list", "list todos") 97 97 .alias("ls") 98 98 .arguments("[status:string]") ··· 103 103 status = maybeStatus; 104 104 } 105 105 const notebooks = all ? hsh.allNotebooks() : [hsh.currentNotebook()]; 106 - await showTodos(notebooks, status); 106 + await showTodos(hsh, notebooks, status); 107 107 }) 108 108 .command("do", "complete a todo") 109 109 .arguments("<path:string> [line:number]")