fix: рекурсивный обход sidebar для вложенных групп
- flattenSidebar поддерживал максимум два уровня вложенности — группы глубже теряли страницы в llms.txt и архиве - Переписан на рекурсивный обход с накоплением префикса групп через `: ` - Раздел «Данные» (4 уровня вложенности) теперь полностью попадает в карту документации
This commit is contained in:
@@ -101,40 +101,41 @@ const linkToSiteUrl = (link: string): string =>
|
||||
|
||||
/**
|
||||
* Развернуть sidebar в плоский список с сохранением группы и
|
||||
* опционального префикса вложенной группы.
|
||||
* накопленного префикса вложенных групп. Поддерживает произвольную
|
||||
* глубину вложенности — префиксы подгрупп склеиваются через `: `.
|
||||
*/
|
||||
const flattenSidebar = (sidebar: SidebarItem[]): Entry[] => {
|
||||
const entries: Entry[] = [];
|
||||
|
||||
for (const top of sidebar) {
|
||||
const section = top.text;
|
||||
const walk = (
|
||||
items: SidebarItem[],
|
||||
section: string,
|
||||
prefix: string | null,
|
||||
): void => {
|
||||
for (const item of items) {
|
||||
const hasChildren = !!item.items && item.items.length > 0;
|
||||
|
||||
if (top.link && !top.items) {
|
||||
entries.push({ section, prefix: null, text: top.text, link: top.link });
|
||||
if (item.link) {
|
||||
entries.push({ section, prefix, text: item.text, link: item.link });
|
||||
}
|
||||
|
||||
if (hasChildren) {
|
||||
const nextPrefix = prefix ? `${prefix}: ${item.text}` : item.text;
|
||||
walk(item.items!, section, nextPrefix);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (const top of sidebar) {
|
||||
const hasChildren = !!top.items && top.items.length > 0;
|
||||
|
||||
if (top.link && !hasChildren) {
|
||||
entries.push({ section: top.text, prefix: null, text: top.text, link: top.link });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!top.items) continue;
|
||||
|
||||
for (const item of top.items) {
|
||||
if (item.items) {
|
||||
for (const sub of item.items) {
|
||||
if (!sub.link) continue;
|
||||
entries.push({
|
||||
section,
|
||||
prefix: item.text,
|
||||
text: sub.text,
|
||||
link: sub.link,
|
||||
});
|
||||
}
|
||||
} else if (item.link) {
|
||||
entries.push({
|
||||
section,
|
||||
prefix: null,
|
||||
text: item.text,
|
||||
link: item.link,
|
||||
});
|
||||
}
|
||||
if (hasChildren) {
|
||||
walk(top.items!, top.text, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user