summaryrefslogtreecommitdiffhomepage
path: root/.rules/plan/calendar-phase-1.md
blob: a1f9b2ee1dab95b1515c42671c3d502be176fe32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Phase 1: Daily Note Manager (`src/calendar/daily-notes.ts`)

**Status:** Not started
**Depends on:** Nothing (standalone)
**Output file:** `src/calendar/daily-notes.ts`

---

## Overview

Core module — no UI, just logic. All daily note path computation, CRUD, indexing, and date detection lives here.

---

## Storage Structure

```
{rootFolder}/{YYYY}/{MM}/{DD}/{YYYY-MM-DD}.md
```

- **`rootFolder`** — configurable, defaults to `"Calendar"`
- **Year** — 4-digit (`2026`)
- **Month** — 2-digit zero-padded (`01`–`12`)
- **Day** — 2-digit zero-padded (`01`–`31`)
- **Filename** — `YYYY-MM-DD.md` (ISO date)

---

## Functions

```
- getDailyNotePath(date: Moment, rootFolder: string): string
    Computes: `{rootFolder}/{YYYY}/{MM}/{DD}/{YYYY-MM-DD}.md`

- getDailyNote(app: App, date: Moment, rootFolder: string): TFile | null
    Looks up vault file at the computed path.

- createDailyNote(app: App, date: Moment, rootFolder: string, template?: string): Promise<TFile>
    Creates parent folders if needed, creates the file.
    Uses template content if configured, else empty with frontmatter:
      ---
      date: YYYY-MM-DD
      ---

- openDailyNote(app: App, date: Moment, rootFolder: string, opts: { newLeaf: boolean }): Promise<void>
    Opens existing note or creates then opens.

- indexDailyNotes(app: App, rootFolder: string): Map<string, TFile>
    Scans `{rootFolder}/` recursively, parses YYYY/MM/DD structure,
    returns Map<"YYYY-MM-DD", TFile>.

- getDateFromDailyNote(file: TFile, rootFolder: string): Moment | null
    Reverse lookup: given a TFile, extract the date if it lives
    in the daily note folder structure.
```

---

## Notes

- `moment.js` is available globally in Obsidian as `window.moment()`. No import needed.
- `indexDailyNotes()` scans only the calendar root folder, not the entire vault.
- Template support: if `calendarDailyNoteTemplate` is set, new daily notes copy that file's content (with `{{date}}` placeholder replacement).
- The `day/` folder can hold multiple notes per day for future expansion, but the calendar UI currently shows one note per day.