"""FlowDeck — Dashboard : public. Découpe A28 de l'ancien app/routers/dashboard.py (2 735 lignes, 63 routes) — un module par concern, contrat inchangé. """ from __future__ import annotations import logging from fastapi import APIRouter, Request from fastapi.responses import HTMLResponse from app.db import get_conn from ._common import _render_blocks_public logger = logging.getLogger(__name__) router = APIRouter(tags=["dashboard"]) # ═══════════ Public Published Page ═══════════ @router.get("/p/{slug}", response_class=HTMLResponse) def public_published_page(request: Request, slug: str): """Serve a published page at /p/ — no auth required.""" from app.templating import ENV with get_conn() as conn: row = conn.execute( "SELECT id, title, content, content_format, updated_at, created_at, cover_url, page_icon " "FROM pages WHERE publish_slug=? AND is_published=1", (slug,), ).fetchone() if not row: return HTMLResponse( """ Not Found — FlowDeck

404

""", status_code=404, ) page = dict(row) env = ENV # Convert blocks to HTML for rendering content_html = "" if page.get("content_format") == "blocks" and page.get("content"): import json as _json try: blocks = _json.loads(page["content"]) from app.services.synced_blocks import resolve_synced_block blocks = resolve_synced_block(blocks) from app.db import get_conn as _gc from app.services.wiki_links import token_labels with _gc() as conn: wiki_titles_map = token_labels(conn, page["content"]) content_html = _render_blocks_public(blocks, wiki_titles_map) except (_json.JSONDecodeError, Exception): content_html = f"

{page.get('content', '')}

" elif page.get("content"): # Plain text / markdown text = page["content"] content_html = f"
{text}
" template = env.get_template("public_page.html") return template.render( title=page["title"] or "Untitled", content_html=content_html, updated_at=page.get("updated_at", ""), created_at=page.get("created_at", ""), cover_url=page.get("cover_url", ""), page_icon=page.get("page_icon", ""), )