From ec01ae2e1c008c5987e686ac27c3c918c6c362ab Mon Sep 17 00:00:00 2001 From: "S.Gromov" Date: Mon, 27 Apr 2026 01:27:35 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=80=D0=B5=D0=BA=D1=83=D1=80=D1=81?= =?UTF-8?q?=D0=B8=D0=B2=D0=BD=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=20sidebar=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - flattenSidebar поддерживал максимум два уровня вложенности — группы глубже теряли страницы в llms.txt и архиве - Переписан на рекурсивный обход с накоплением префикса групп через `: ` - Раздел «Данные» (4 уровня вложенности) теперь полностью попадает в карту документации --- generate-llms.ts | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/generate-llms.ts b/generate-llms.ts index d779bf8..e197db7 100644 --- a/generate-llms.ts +++ b/generate-llms.ts @@ -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); } }