File size: 1,144 Bytes
42e32ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import argparse
from datetime import datetime
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
JOURNAL_DIR = ROOT / "docs" / "journal"


TEMPLATE = """# {title}

Date: {timestamp}

## Built

- 

## Decisions

- 

## Learned

- 

## Next

- 
"""


def slugify(value: str) -> str:
    safe = "".join(ch.lower() if ch.isalnum() else "-" for ch in value).strip("-")
    return "-".join(part for part in safe.split("-") if part)[:64] or "entry"


def main() -> None:
    parser = argparse.ArgumentParser(description="Create a dated build journal entry.")
    parser.add_argument("title", help="Short title for the journal entry")
    args = parser.parse_args()

    JOURNAL_DIR.mkdir(parents=True, exist_ok=True)
    now = datetime.now().astimezone()
    path = JOURNAL_DIR / f"{now:%Y-%m-%d}-{slugify(args.title)}.md"
    if path.exists():
        raise SystemExit(f"Entry already exists: {path}")
    path.write_text(TEMPLATE.format(title=args.title, timestamp=now.isoformat(timespec="seconds")), encoding="utf-8")
    print(path.relative_to(ROOT))


if __name__ == "__main__":
    main()