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