c34dab2cca
Build and Push Docker Container / build-and-push (push) Successful in 4m28s
- Create missing note files before running property:set. - Default date-only datetime values to midnight. - Keep property names out of path authorization checks. - Split policy, vault, daily note, and command target helpers. - Split n8n node args, description, output, and API response helpers. - Split API tests by auth, command, daily note, and property behavior. - Bump API and n8n node versions.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from datetime import datetime
|
|
from pathlib import Path
|
|
import json
|
|
|
|
def moment_to_strftime(format_string:str) -> str:
|
|
replacements = [
|
|
("YYYY", "%Y"),
|
|
("YY", "%y"),
|
|
("MMMM", "%B"),
|
|
("MMM", "%b"),
|
|
("MM", "%m"),
|
|
("DDDD", "%j"),
|
|
("DD", "%d"),
|
|
("dddd", "%A"),
|
|
("ddd", "%a"),
|
|
]
|
|
converted = format_string or "YYYY-MM-DD"
|
|
for moment_token, strftime_token in replacements:
|
|
converted = converted.replace(moment_token, strftime_token)
|
|
return converted
|
|
|
|
def daily_note_path_for_vault(vault_root:Path, now:datetime|None = None) -> str:
|
|
settings_path = vault_root / ".obsidian" / "daily-notes.json"
|
|
folder = ""
|
|
format_string = "YYYY-MM-DD"
|
|
|
|
if settings_path.exists() and settings_path.is_file():
|
|
try:
|
|
settings = json.loads(settings_path.read_text(encoding="utf-8"))
|
|
if isinstance(settings, dict):
|
|
folder_value = settings.get("folder")
|
|
format_value = settings.get("format")
|
|
if isinstance(folder_value, str):
|
|
folder = folder_value.strip().strip("/")
|
|
if isinstance(format_value, str) and format_value.strip():
|
|
format_string = format_value.strip()
|
|
except (OSError, json.JSONDecodeError):
|
|
pass
|
|
|
|
note_name = (now or datetime.now()).strftime(moment_to_strftime(format_string))
|
|
if not note_name.endswith(".md"):
|
|
note_name += ".md"
|
|
return f"{folder}/{note_name}" if folder else note_name
|