Verkuerze die Inhaltsliste und fuehre Unterkapitel ein, damit Richtung, Bezuge und Struktur ohne Zusatzzeilen bedienbar bleiben.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
eeeb81148a
commit
e4380261fc
30 files changed
+2384
-430
No files matched your search
+45
-19
@@ -252,22 +252,7 @@ def _matter_node(conn, actor, matter, page: Ctx, root: bool) -> ExportNode:
|
||||
for binding in bindings:
|
||||
grouped.setdefault(binding.get("chapter_id"), []).append(binding)
|
||||
children: list[ExportNode] = []
|
||||
for chapter in chapters:
|
||||
items = grouped.get(chapter["id"], [])
|
||||
if not items:
|
||||
continue
|
||||
children.append(
|
||||
ExportNode(
|
||||
id=f"chapter:{chapter['id']}",
|
||||
kind="chapter",
|
||||
title=chapter["title"],
|
||||
exportable=True,
|
||||
reason=None,
|
||||
content_kind=None,
|
||||
children=[_binding_node(item) for item in items],
|
||||
label="Kapitel",
|
||||
)
|
||||
)
|
||||
children.extend(_chapter_nodes(chapters, grouped))
|
||||
for binding in grouped.get(None, []):
|
||||
children.append(_binding_node(binding))
|
||||
rows = conn.execute(
|
||||
@@ -290,6 +275,35 @@ def _matter_node(conn, actor, matter, page: Ctx, root: bool) -> ExportNode:
|
||||
)
|
||||
|
||||
|
||||
def _chapter_nodes(chapters: list[dict], grouped: dict[str | None, list]) -> list[ExportNode]:
|
||||
by_parent: dict[str | None, list[dict]] = {}
|
||||
for chapter in chapters:
|
||||
by_parent.setdefault(chapter.get("parent_chapter_id"), []).append(chapter)
|
||||
|
||||
def build(parent_id: str | None) -> list[ExportNode]:
|
||||
nodes: list[ExportNode] = []
|
||||
for chapter in by_parent.get(parent_id, []):
|
||||
nested = build(chapter["id"])
|
||||
items = [_binding_node(item) for item in grouped.get(chapter["id"], [])]
|
||||
if not items and not nested:
|
||||
continue
|
||||
nodes.append(
|
||||
ExportNode(
|
||||
id=f"chapter:{chapter['id']}",
|
||||
kind="chapter",
|
||||
title=chapter["title"],
|
||||
exportable=True,
|
||||
reason=None,
|
||||
content_kind=None,
|
||||
children=[*items, *nested],
|
||||
label="Unterkapitel" if parent_id else "Kapitel",
|
||||
)
|
||||
)
|
||||
return nodes
|
||||
|
||||
return build(None)
|
||||
|
||||
|
||||
def _binding_node(binding: dict) -> ExportNode:
|
||||
element = binding["element"]
|
||||
rights = binding["rights"]
|
||||
@@ -454,7 +468,7 @@ def _layout(root, chosen, loaded, notices, generated: str):
|
||||
numbers = {child.id: index + 1 for index, child in enumerate(folders)}
|
||||
for child in node.children:
|
||||
if child.id in numbers:
|
||||
folder = prefix + [f"{numbers[child.id]:02d} {_segment(child.title)}"]
|
||||
folder = prefix + [_folder_name(child.title, numbers[child.id], prefix)]
|
||||
if child.kind == "binding" and child.content_kind == "email":
|
||||
_emit_email(child, folder, add, rewrite, entries, loaded, notice_for, generated)
|
||||
else:
|
||||
@@ -726,7 +740,7 @@ def _recorded(node: ExportNode) -> str | None:
|
||||
return node.dates.get("recorded_at")
|
||||
|
||||
|
||||
def _segment(value: str) -> str:
|
||||
def _segment(value: str, limit: int = 80) -> str:
|
||||
cleaned = []
|
||||
for char in value or "":
|
||||
if char in '\\/:*?"<>|' or ord(char) < 32:
|
||||
@@ -734,7 +748,19 @@ def _segment(value: str) -> str:
|
||||
else:
|
||||
cleaned.append(char)
|
||||
text = " ".join("".join(cleaned).split()).strip(" .")
|
||||
return (text or "Inhalt")[:80]
|
||||
if text in {"", ".", ".."}:
|
||||
text = "Inhalt"
|
||||
return text[:limit]
|
||||
|
||||
|
||||
def _folder_name(title: str, number: int, prefix: list[str]) -> str:
|
||||
"""Keep a readable directory name inside a bounded path. The overview keeps the full title."""
|
||||
limit = 80
|
||||
while True:
|
||||
name = f"{number:02d} {_segment(title, limit)}"
|
||||
if len("/".join([*prefix, name])) <= 180 or limit <= 24:
|
||||
return name
|
||||
limit -= 8
|
||||
|
||||
|
||||
def _file_segment(value: str) -> str:
|
||||
|
||||
Reference in new issue
Block a user