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:
@@ -1814,8 +1814,12 @@ async def article_edit(article_id: int):
|
||||
await flash("Article updated.", "success")
|
||||
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"
|
||||
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 ""
|
||||
|
||||
data = {**dict(article), "body": body}
|
||||
|
||||
@@ -135,7 +135,7 @@ def _validate_table_name(data_table: str) -> None:
|
||||
|
||||
def _datetimeformat(value: str, fmt: str = "%Y-%m-%d") -> str:
|
||||
"""Jinja2 filter: format a date string (or 'now') with strftime."""
|
||||
from datetime import datetime, UTC
|
||||
from datetime import UTC, datetime
|
||||
|
||||
if value == "now":
|
||||
dt = datetime.now(UTC)
|
||||
@@ -429,6 +429,11 @@ async def generate_articles(
|
||||
build_dir.mkdir(parents=True, exist_ok=True)
|
||||
(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
|
||||
existing_article = await fetch_one(
|
||||
"SELECT id FROM articles WHERE url_path = ?", (url_path,),
|
||||
|
||||
Reference in New Issue
Block a user