Verkuerze die Inhaltsliste und fuehre Unterkapitel ein, damit Richtung, Bezuge und Struktur ohne Zusatzzeilen bedienbar bleiben.
Deploy Development / deploy (push) Successful in 29s
Test Suite / pytest-backend (push) Successful in 1m24s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 9s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 21:13:21 +02:00
1 parent eeeb81148a
commit e4380261fc
30 files changed
+2384 -430

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
export function chapterPath(chapters, chapterId) {
const byId = new Map((chapters || []).map((chapter) => [chapter.id, chapter]));
const names = [];
const seen = new Set();
let current = byId.get(chapterId);
while (current && !seen.has(current.id)) {
seen.add(current.id);
names.unshift(current.title);
current = current.parent_chapter_id ? byId.get(current.parent_chapter_id) : null;
}
return names;
}
export function chapterPathLabel(chapters, chapterId) {
return chapterPath(chapters, chapterId).join(" / ");
}
export function siblingChapterIds(chapters, chapterId) {
const current = (chapters || []).find((chapter) => chapter.id === chapterId);
const parent = current?.parent_chapter_id || null;
return (chapters || [])
.filter((chapter) => (chapter.parent_chapter_id || null) === parent)
.map((chapter) => chapter.id);
}
export function descendantChapterIds(chapters, chapterId) {
const children = (chapters || []).filter((chapter) => chapter.parent_chapter_id === chapterId);
return children.flatMap((chapter) => [chapter.id, ...descendantChapterIds(chapters, chapter.id)]);
}
export function buildChapterSections(chapters, bindings) {
const buckets = new Map();
const loose = [];
const known = new Set((chapters || []).map((chapter) => chapter.id));
for (const binding of bindings || []) {
if (binding.chapter_id && known.has(binding.chapter_id)) {
const list = buckets.get(binding.chapter_id) || [];
list.push(binding);
buckets.set(binding.chapter_id, list);
} else {
loose.push(binding);
}
}
const nodes = new Map();
for (const chapter of chapters || []) {
nodes.set(chapter.id, {
id: chapter.id,
title: chapter.title,
documentOn: chapter.document_on || "",
parentId: chapter.parent_chapter_id || "",
items: buckets.get(chapter.id) || [],
children: [],
});
}
const roots = [];
for (const chapter of chapters || []) {
const node = nodes.get(chapter.id);
const parent = chapter.parent_chapter_id ? nodes.get(chapter.parent_chapter_id) : null;
if (parent) parent.children.push(node);
else roots.push(node);
}
return { roots, loose };
}
export function trailWithChapter(items, chapters, chapterId, backHref) {
if (!chapterId) return items;
const path = chapterPath(chapters, chapterId);
if (!path.length) return items || [];
const base = (items || []).map((item, index, all) => (
index === all.length - 1 && !item.href ? { ...item, href: backHref } : item
));
return [...base, { label: path.join(" / "), href: null }];
}
export function findSection(nodes, id) {
for (const node of nodes || []) {
if (node.id === id) return node;
const found = findSection(node.children, id);
if (found) return found;
}
return null;
}