feat: filename template expansion with {date} placeholder

- Add expand_filename_template() to yaml_config.py
- Supports {author}, {from}, {to}, {date}, {ext} placeholders
- {date} formats as DD_MM_YYYY (e.g. 31_03_2026)
- Spaces in author replaced with underscores for safe filenames
- Unknown placeholders left as-is
- Add comprehensive CONFIG.md documentation covering YAML setup, migration, and template syntax
This commit is contained in:
Кокос Артем Николаевич
2026-07-03 18:13:55 +07:00
parent c962a93f30
commit b1a565bc9e
4 changed files with 277 additions and 2 deletions

View File

@@ -56,3 +56,46 @@ def check_file_permissions(path: Path) -> list[str]:
f"Expected 0600. Fix with: chmod 600 {path}"
)
return warnings
def expand_filename_template(
template: str,
*,
author: str = "",
from_date: str = "",
to_date: str = "",
ext: str = "",
) -> str:
"""Expand placeholders in a filename template.
Supported placeholders:
{author} — author name
{from} — start date (YYYY-MM-DD)
{to} — end date (YYYY-MM-DD)
{date} — end date formatted as DD_MM_YYYY
{ext} — file extension without dot
Unknown placeholders are left as-is.
"""
date_dd_mm_yyyy = ""
if to_date:
try:
from datetime import datetime
dt = datetime.strptime(to_date, "%Y-%m-%d")
date_dd_mm_yyyy = dt.strftime("%d_%m_%Y")
except ValueError:
date_dd_mm_yyyy = to_date
replacements = {
"author": author.replace(" ", "_"),
"from": from_date,
"to": to_date,
"date": date_dd_mm_yyyy,
"ext": ext,
}
result = template
for key, value in replacements.items():
result = result.replace("{" + key + "}", value)
return result