diff --git a/src/.vitepress/config.mts b/src/.vitepress/config.mts index 39178fb..b0335fc 100644 --- a/src/.vitepress/config.mts +++ b/src/.vitepress/config.mts @@ -3,6 +3,7 @@ import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs' import { overrideComponents } from './override-components' import { autoSectionLinksPlugin } from './plugins/auto-section-links' import { resolve } from 'path' +import { SidebarItem } from './plugins/utils/types' const gitlab = ` const new_version = process.env?.VITE_NEW_VERSION; console.log({ base: typeof new_version !== 'undefined' ? '/' : '/docs/' }) + const sidebarConfig = { '/platform/': [ { @@ -181,7 +183,7 @@ const sidebarConfig = { { text: 'Квоты и лимиты', link: '/compute/compute-quatos.md' }, ] }, - {text: 'Быстрый старт', link: '/compute/compute-getting-started.md'}, + {text: 'Быстрый старт', link: '/compute/compute-getting-started.md', excludeFromIndex: true }, { text: 'Виртуальные машины', link: '/compute/compute-how-to/compute-index.md', collapsed: true, items: [ @@ -207,6 +209,7 @@ const sidebarConfig = { { text: 'Настройка site-to-site VPN с помощью VyOS', link: '/compute/compute-how-to/compute-network/compute-vpn-vyos.md' }, { text: 'Подключение ВМ закрытого контура к интернету', link: '/compute/compute-how-to/compute-network/compute-network-inside.md' }, ], + excludeFromIndex: true, }, ], '/admin/': [ diff --git a/src/.vitepress/plugins/utils/frontmatter.ts b/src/.vitepress/plugins/utils/frontmatter.ts index e43f530..6084ad9 100644 --- a/src/.vitepress/plugins/utils/frontmatter.ts +++ b/src/.vitepress/plugins/utils/frontmatter.ts @@ -17,7 +17,7 @@ export const parseFrontmatter = (content: string) => { const lines = frontmatterText.split('\n') let currentKey: string | undefined let currentValue: SectionLinkListItem[] = [] - let currentItem: Partial | undefined + let currentItem: Record | undefined let inArray = false for (const line of lines) { @@ -51,8 +51,15 @@ export const parseFrontmatter = (content: string) => { currentValue = [] } - if (currentItem && !currentValue.includes(currentItem as SectionLinkListItem)) { - currentValue.push(currentItem as SectionLinkListItem) + if (currentItem && currentItem.title && currentItem.link !== undefined) { + const link: SectionLinkListItem = { + title: currentItem.title, + link: currentItem.link, + description: currentItem.description + } + if (!currentValue.some(item => item.link === link.link)) { + currentValue.push(link) + } } const itemText = trimmed.slice(2).trim() @@ -63,9 +70,8 @@ export const parseFrontmatter = (content: string) => { const colonMatch = part.match(/^(\w+):\s*(.+)$/) if (colonMatch) { const [, key, value] = colonMatch - const sectionKey = key as keyof SectionLinkListItem - if (SECTION_LINK_KEYS.includes(sectionKey)) { - currentItem[sectionKey] = value.replace(/^["']|["']$/g, '') + if (SECTION_LINK_KEYS.includes(key as typeof SECTION_LINK_KEYS[number])) { + currentItem[key] = value.replace(/^["']|["']$/g, '') } } } @@ -77,17 +83,23 @@ export const parseFrontmatter = (content: string) => { if (colonIndex !== -1) { const key = trimmed.substring(0, colonIndex).trim() const value = trimmed.substring(colonIndex + 1).trim() - const sectionKey = key as keyof SectionLinkListItem - if (SECTION_LINK_KEYS.includes(sectionKey)) { - currentItem[sectionKey] = value === '' ? '' : value.replace(/^["']|["']$/g, '') + if (SECTION_LINK_KEYS.includes(key as typeof SECTION_LINK_KEYS[number])) { + currentItem[key] = value === '' ? '' : value.replace(/^["']|["']$/g, '') } } } } } - if (currentItem && inArray && !currentValue.includes(currentItem as SectionLinkListItem)) { - currentValue.push(currentItem as SectionLinkListItem) + if (currentItem && inArray && currentItem.title && currentItem.link !== undefined) { + const link: SectionLinkListItem = { + title: currentItem.title, + link: currentItem.link, + description: currentItem.description + } + if (!currentValue.some(item => item.link === link.link)) { + currentValue.push(link) + } } if (inArray && currentKey) { frontmatter[currentKey] = currentValue diff --git a/src/.vitepress/plugins/utils/links.ts b/src/.vitepress/plugins/utils/links.ts index 121e745..62bdf32 100644 --- a/src/.vitepress/plugins/utils/links.ts +++ b/src/.vitepress/plugins/utils/links.ts @@ -59,6 +59,10 @@ export const extractTopLevelLinks = ( const normalizedCurrentPath = normalizeLink(currentIndexPath) for (const item of items) { + if ('excludeFromIndex' in item && item.excludeFromIndex) { + continue + } + if (item.link) { const normalizedItemPath = normalizeLink(item.link) if (normalizedItemPath === normalizedCurrentPath) { @@ -90,6 +94,10 @@ const findItemsRecursive = ( if (normalizedItemPath === normalizedPagePath && item.items && Array.isArray(item.items) && item.items.length > 0) { for (const subItem of item.items) { + if ('excludeFromIndex' in subItem && subItem.excludeFromIndex) { + continue + } + if (subItem.link) { links.push({ title: subItem.text || '', diff --git a/src/.vitepress/plugins/utils/types.ts b/src/.vitepress/plugins/utils/types.ts index b9e18ba..f003f3e 100644 --- a/src/.vitepress/plugins/utils/types.ts +++ b/src/.vitepress/plugins/utils/types.ts @@ -8,5 +8,5 @@ export type SidebarItem = { export type Frontmatter = { section_links?: SectionLinkListItem[] - [key: string]: any + [key: string]: string | number | boolean | string[] | SectionLinkListItem[] | undefined } diff --git a/src/.vitepress/theme/components/SectionLinkList/SectionLinkList.types.ts b/src/.vitepress/theme/components/SectionLinkList/SectionLinkList.types.ts index 54208d0..a35b918 100644 --- a/src/.vitepress/theme/components/SectionLinkList/SectionLinkList.types.ts +++ b/src/.vitepress/theme/components/SectionLinkList/SectionLinkList.types.ts @@ -2,6 +2,8 @@ export type SectionLinkListItem = { title: string, link: string, description?: string + collapsed?: boolean + excludeFromIndex?: boolean } export type SectionLinkListProps = { diff --git a/src/compute/index.md b/src/compute/index.md index 7e24d8a..37de449 100644 --- a/src/compute/index.md +++ b/src/compute/index.md @@ -3,8 +3,6 @@ section_links: - title: Обзор сервиса link: /compute/compute-overview-index.md description: Обзор сервиса, решаемые задачи, характеристики оборудования - - title: Быстрый старт - link: /compute/compute-getting-started.md - title: Виртуальные машины link: /compute/compute-how-to/compute-index.md description: Создание виртуальной машины и подключение к ней, управление виртуальной машиной @@ -17,8 +15,6 @@ section_links: - title: Группы размещения link: /compute/compute-how-to/compute-affinity.md description: Создание правил размещения виртуальных машин на физических хостах, управление группами размещения - - title: Сети - link: /compute/compute-how-to/compute-network/compute-network-index.md --- # Виртуальные машины