Skip to content

Commit

Permalink
Merge pull request #45 from HiDeoo/hd-fix-sidebar-badges
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed May 11, 2024
2 parents f5dbcf8 + c6a495d commit 95b6a37
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/astro.multiple-plugins.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default defineConfig({
sidebar: [
{
label: 'Bar Content',
items: [barTypeDocSidebarGroup],
items: [{ ...barTypeDocSidebarGroup, badge: 'generated' }],
},
{
label: 'Foo Content',
Expand Down
9 changes: 8 additions & 1 deletion packages/starlight-typedoc/libs/starlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight-typedoc/tests/e2e/fixtures/DocPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
})
}
Expand Down
8 changes: 8 additions & 0 deletions packages/starlight-typedoc/tests/e2e/plugins/sidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit 95b6a37

Please sign in to comment.