feat: write markdown to disk during generation for admin editing

- generate_articles() now writes body_md alongside body_html
  to BUILD_DIR/{lang}/md/{slug}.md
- article_edit GET checks both manual and generated markdown paths
- Fix pre-existing ruff import sort in _datetimeformat

Subtask 5 of CMS admin improvement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-02-24 01:18:48 +01:00
parent f0f6e7542f
commit 8ae5aa1935
2 changed files with 11 additions and 2 deletions

View File

@@ -1814,8 +1814,12 @@ async def article_edit(article_id: int):
await flash("Article updated.", "success") await flash("Article updated.", "success")
return redirect(url_for("admin.articles")) return redirect(url_for("admin.articles"))
# Load markdown source if available # Load markdown source if available (manual or generated)
from ..content.routes import BUILD_DIR as CONTENT_BUILD_DIR
md_path = Path("data/content/articles") / f"{article['slug']}.md" md_path = Path("data/content/articles") / f"{article['slug']}.md"
if not md_path.exists():
lang = article["language"] or "en"
md_path = CONTENT_BUILD_DIR / lang / "md" / f"{article['slug']}.md"
body = md_path.read_text() if md_path.exists() else "" body = md_path.read_text() if md_path.exists() else ""
data = {**dict(article), "body": body} data = {**dict(article), "body": body}

View File

@@ -135,7 +135,7 @@ def _validate_table_name(data_table: str) -> None:
def _datetimeformat(value: str, fmt: str = "%Y-%m-%d") -> str: def _datetimeformat(value: str, fmt: str = "%Y-%m-%d") -> str:
"""Jinja2 filter: format a date string (or 'now') with strftime.""" """Jinja2 filter: format a date string (or 'now') with strftime."""
from datetime import datetime, UTC from datetime import UTC, datetime
if value == "now": if value == "now":
dt = datetime.now(UTC) dt = datetime.now(UTC)
@@ -429,6 +429,11 @@ async def generate_articles(
build_dir.mkdir(parents=True, exist_ok=True) build_dir.mkdir(parents=True, exist_ok=True)
(build_dir / f"{article_slug}.html").write_text(body_html) (build_dir / f"{article_slug}.html").write_text(body_html)
# Write markdown source to disk (for admin editing)
md_dir = BUILD_DIR / lang / "md"
md_dir.mkdir(parents=True, exist_ok=True)
(md_dir / f"{article_slug}.md").write_text(body_md)
# Upsert article in SQLite # Upsert article in SQLite
existing_article = await fetch_one( existing_article = await fetch_one(
"SELECT id FROM articles WHERE url_path = ?", (url_path,), "SELECT id FROM articles WHERE url_path = ?", (url_path,),