diff --git a/api/advent22_api/core/config.py b/api/advent22_api/core/config.py index 1f6ba42..d1cdb1a 100644 --- a/api/advent22_api/core/config.py +++ b/api/advent22_api/core/config.py @@ -3,7 +3,8 @@ import tomllib from enum import Enum from random import Random -from pydantic import BaseModel, field_validator +from markdown import markdown +from pydantic import BaseModel, ConfigDict, field_validator from .dav.webdav import WebDAV from .settings import SETTINGS @@ -25,6 +26,8 @@ class TransformedString(BaseModel): # whitespace entfernen IGNORE = "IGNORE" + # special chars + class __Case(str, Enum): # unverändert KEEP = "KEEP" @@ -78,10 +81,27 @@ class TransformedString(BaseModel): return result -class Puzzle(BaseModel): +class Site(BaseModel): + model_config = ConfigDict(validate_default=True) + # Titel title: str + # Untertitel + subtitle: str + + # Inhalt der Seite + content: str + + # Fußzeile der Seite + footer: str = "**Advent22** by [Lenaisten e.V.](//www.lenaisten.de)" + + @field_validator("content", "footer", mode="after") + def parse_md(cls, v) -> str: + return markdown(v) + + +class Puzzle(BaseModel): # Tag, an dem der Kalender startet begin_day: int = 1 @@ -108,6 +128,7 @@ class Config(BaseModel): solution: TransformedString # Weitere Einstellungen + site: Site puzzle: Puzzle image: Image @@ -117,11 +138,6 @@ class Config(BaseModel): # Serverseitiger zusätzlicher "random" seed random_seed: str = "" - # Fußzeile der Seite - footer: str = ( - 'Advent22 by Lenaisten e.V.' - ) - async def get_config() -> Config: """ diff --git a/api/advent22_api/routers/user.py b/api/advent22_api/routers/user.py index e6c19c0..65ca8d4 100644 --- a/api/advent22_api/routers/user.py +++ b/api/advent22_api/routers/user.py @@ -5,7 +5,7 @@ from fastapi.responses import StreamingResponse from PIL import Image from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config -from ..core.config import Config, get_config +from ..core.config import Config, Site, get_config from ..core.depends import get_all_event_dates, get_day_image from ..core.helpers import EventDates, api_return_ico, api_return_jpeg, load_image from ._security import user_can_view_day, user_is_admin, user_visible_days @@ -45,19 +45,15 @@ async def get_favicon( raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) -# - favicon -# - "user-config-model" - - -@router.get("/title") -async def get_title( +@router.get("/site_config") +async def get_site_config( cfg: Config = Depends(get_config), -) -> str: +) -> Site: """ - Lädt Kalendertitel + Seiteninhalt """ - return cfg.puzzle.title + return cfg.site @router.get("/doors") @@ -72,17 +68,6 @@ async def get_doors( return [door for door in cal_cfg.doors if door.day in visible_days] -@router.get("/footer") -async def get_footer( - cfg: Config = Depends(get_config), -) -> str: - """ - Seiten-Fußzeile lesen - """ - - return cfg.footer - - @router.get( "/image_{day}", response_class=StreamingResponse, diff --git a/api/poetry.lock b/api/poetry.lock index 36f6d09..a2ce73c 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -580,6 +580,21 @@ html5 = ["html5lib"] htmlsoup = ["BeautifulSoup4"] source = ["Cython (>=0.29.35)"] +[[package]] +name = "markdown" +version = "3.5.1" +description = "Python implementation of John Gruber's Markdown." +optional = false +python-versions = ">=3.8" +files = [ + {file = "Markdown-3.5.1-py3-none-any.whl", hash = "sha256:5874b47d4ee3f0b14d764324d2c94c03ea66bee56f2d929da9f2508d65e722dc"}, + {file = "Markdown-3.5.1.tar.gz", hash = "sha256:b65d7beb248dc22f2e8a31fb706d93798093c308dc1aba295aedeb9d41a813bd"}, +] + +[package.extras] +docs = ["mdx-gh-links (>=0.2)", "mkdocs (>=1.5)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"] +testing = ["coverage", "pyyaml"] + [[package]] name = "mccabe" version = "0.7.0" @@ -1376,4 +1391,4 @@ typing-extensions = ">=4.4.0" [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.13" -content-hash = "e97f2ab7e4314a0b6ce3725b8068a147a06e5ac5c9ee8e5406ca546dac3075cd" +content-hash = "73d5978c4787027b57334c5e5ac98df12e7b9e958bc92a5c326b512861986c57" diff --git a/api/pyproject.toml b/api/pyproject.toml index 9508c7f..7087996 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -21,6 +21,7 @@ redis = {extras = ["hiredis"], version = "^5.0.1"} tomli-w = "^1.0.0" uvicorn = {extras = ["standard"], version = "^0.23.2"} webdavclient3 = "^3.14.6" +markdown = "^3.5.1" [tool.poetry.group.dev.dependencies] black = "^23.10.1" diff --git a/ui/src/App.vue b/ui/src/App.vue index 36ea67a..dda4ded 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -1,8 +1,8 @@