quality / commitlint (push) Skipped
CD / update-wiki (push) Successful in 8s
quality / changes (push) Successful in 9s
quality / api (push) Skipped
quality / docker-check (push) Skipped
quality / web (push) Successful in 1m2s
CD / quality (push) Successful in 1m15s
CD / publish (push) Successful in 1m58s
Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
export interface BreadcrumbCrumb {
|
|
label: string
|
|
href: string
|
|
}
|
|
|
|
const routeTitles: Record<string, string> = {
|
|
'/': 'Панель управления',
|
|
'/domains': 'Домены',
|
|
'/groups': 'Группы доменов',
|
|
'/services': 'Сервисы',
|
|
'/certificates': 'Сертификаты',
|
|
}
|
|
|
|
const SETTINGS_SECTIONS: Record<string, string> = {
|
|
'/settings/appearance': 'Внешний вид',
|
|
'/settings/health': 'Health-check',
|
|
'/settings/integrations': 'Интеграции',
|
|
}
|
|
|
|
/** Drop consecutive repeats so «Настройки» does not stack after tab switches. */
|
|
export function dedupeBreadcrumbs(crumbs: BreadcrumbCrumb[]): BreadcrumbCrumb[] {
|
|
const out: BreadcrumbCrumb[] = []
|
|
for (const crumb of crumbs) {
|
|
const prev = out.at(-1)
|
|
if (prev && prev.label === crumb.label) continue
|
|
out.push(crumb)
|
|
}
|
|
return out
|
|
}
|
|
|
|
export function getBreadcrumbs(
|
|
pathname: string,
|
|
dynamicLabels: Record<string, string> = {},
|
|
): BreadcrumbCrumb[] {
|
|
const path = pathname.replace(/\/+$/, '') || '/'
|
|
|
|
if (path === '/') {
|
|
return [{ label: 'Панель управления', href: '/' }]
|
|
}
|
|
|
|
if (path.match(/^\/services\/\d+$/)) {
|
|
return [
|
|
{ label: 'Сервисы', href: '/services' },
|
|
{ label: dynamicLabels[path] ?? 'Сервис', href: path },
|
|
]
|
|
}
|
|
|
|
if (path.match(/^\/groups\/\d+$/)) {
|
|
return [
|
|
{ label: 'Группы доменов', href: '/groups' },
|
|
{ label: dynamicLabels[path] ?? 'Группа', href: path },
|
|
]
|
|
}
|
|
|
|
if (path.match(/^\/domains\/\d+\/dns$/)) {
|
|
const domainId = path.split('/')[2]
|
|
const domainPath = `/domains/${domainId}`
|
|
return [
|
|
{ label: 'Домены', href: '/domains' },
|
|
{ label: dynamicLabels[domainPath] ?? 'Домен', href: domainPath },
|
|
{ label: 'DNS', href: path },
|
|
]
|
|
}
|
|
|
|
if (path.match(/^\/domains\/\d+$/)) {
|
|
return [
|
|
{ label: 'Домены', href: '/domains' },
|
|
{ label: dynamicLabels[path] ?? 'Обзор домена', href: path },
|
|
]
|
|
}
|
|
|
|
if (path === '/settings' || path.startsWith('/settings/')) {
|
|
const section = SETTINGS_SECTIONS[path]
|
|
return dedupeBreadcrumbs([
|
|
{ label: 'Настройки', href: '/settings' },
|
|
...(section ? [{ label: section, href: path }] : []),
|
|
])
|
|
}
|
|
|
|
const title = routeTitles[path]
|
|
if (title) {
|
|
return [{ label: title, href: path }]
|
|
}
|
|
|
|
return [{ label: 'Панель управления', href: '/' }]
|
|
}
|