from datetime import UTC, datetime from soapbox import db from soapbox.content import dump_frontmatter, parse_frontmatter from soapbox.images import process_image from soapbox.render import relative_to, render_markdown from soapbox.slug import slugify, unique_slug from tests.conftest import png_bytes def test_slugify_norwegian(): assert slugify("Grønt er skjønt: blåbær & øl!") == "grønt-er-skjønt-blåbær-øl" assert slugify("Hello, World_2!") == "hello-world-2" assert slugify("Blåbær") == slugify("Bla\u030abær") # NFD → NFC assert slugify("日本語 タイトル") == "日本語-タイトル" assert slugify(" ") == "post" assert unique_slug("a", {"a", "a-2"}) == "a-3" def test_frontmatter_roundtrip(): meta = {"title": 'Tittel: med "anførsel"', "date": "2026-01-01T00:00:00+00:00", "draft": True} text = dump_frontmatter(meta, "# Hei\n\nbrødtekst") parsed, body = parse_frontmatter(text) assert parsed == meta assert body.strip() == "# Hei\n\nbrødtekst" def test_relative_paths(): assert relative_to("", "post1/") == "post1/" assert relative_to("post1/", "") == "../" assert relative_to("gjest/post1/", "post2/") == "../../post2/" assert relative_to("gjest/post1/", "theme/style.css") == "../../theme/style.css" def test_markdown_safe_and_relative(): html = render_markdown("\n\n[a](/post2/#x) ![](b.jpg)", "g/p/") assert "