diff --git a/example/astro.multiple-plugins.config.ts b/example/astro.multiple-plugins.config.ts index 5545401..10fd3c9 100644 --- a/example/astro.multiple-plugins.config.ts +++ b/example/astro.multiple-plugins.config.ts @@ -30,7 +30,7 @@ export default defineConfig({ sidebar: [ { label: 'Bar Content', - items: [barTypeDocSidebarGroup], + items: [{ ...barTypeDocSidebarGroup, badge: 'generated' }], }, { label: 'Foo Content', diff --git a/packages/starlight-typedoc/libs/starlight.ts b/packages/starlight-typedoc/libs/starlight.ts index 10d7b6d..44947f2 100644 --- a/packages/starlight-typedoc/libs/starlight.ts +++ b/packages/starlight-typedoc/libs/starlight.ts @@ -43,7 +43,7 @@ export function getSidebarFromReflections( function replaceSidebarGroupPlaceholder(group: SidebarManualGroup): SidebarGroup { if (group.label === sidebarGroupPlaceholder.label) { - return sidebarGroup + return group.badge ? { ...sidebarGroup, badge: group.badge } : sidebarGroup } if (isSidebarManualGroup(group)) { @@ -252,6 +252,13 @@ interface SidebarManualGroup { collapsed?: boolean items: (LinkItem | SidebarGroup)[] label: string + badge?: + | string + | { + text: string + variant: 'note' | 'danger' | 'success' | 'caution' | 'tip' | 'default' + } + | undefined } interface LinkItem { diff --git a/packages/starlight-typedoc/tests/e2e/fixtures/DocPage.ts b/packages/starlight-typedoc/tests/e2e/fixtures/DocPage.ts index 419c01f..686a090 100644 --- a/packages/starlight-typedoc/tests/e2e/fixtures/DocPage.ts +++ b/packages/starlight-typedoc/tests/e2e/fixtures/DocPage.ts @@ -75,7 +75,7 @@ export class DocPage { for (const category of await list.locator('> li > details').all()) { items.push({ collapsed: !(await category.getAttribute('open')), - label: await category.locator(`> summary > div > span`).textContent(), + label: await category.locator(`> summary > div > span:not(.sl-badge)`).textContent(), items: await this.#getTypeDocSidebarChildrenItems(category.locator('> ul')), }) } diff --git a/packages/starlight-typedoc/tests/e2e/plugins/sidebar.test.ts b/packages/starlight-typedoc/tests/e2e/plugins/sidebar.test.ts index 1c32f99..880c4b1 100644 --- a/packages/starlight-typedoc/tests/e2e/plugins/sidebar.test.ts +++ b/packages/starlight-typedoc/tests/e2e/plugins/sidebar.test.ts @@ -42,3 +42,11 @@ test('should generate the proper items for for multiple plugins with different c }, ]) }) + +test('should support having a badge', async ({ docPage }) => { + docPage.useMultiplePlugins() + + await docPage.goto('api-multiple-plugins-bar/classes/bar') + + await expect(docPage.page.locator('.sl-badge:has-text("generated")')).toBeVisible() +})