Skip to content

Commit

Permalink
Merge pull request #41 from HiDeoo/hd-fix-packages-entrypoint-strateg…
Browse files Browse the repository at this point in the history
…y-broken-links
  • Loading branch information
HiDeoo committed Apr 18, 2024
2 parents f03aaf9 + 2fb04e3 commit 356b61e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
17 changes: 17 additions & 0 deletions fixtures/packages/packages/bar/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,20 @@
export function doBar() {
return 'doBar'
}

/**
* A function that does another bar thing but better.
*
* This is a better alternative to {@link doBar}.
*/
export function doBarBetter(options: DoBarBetterOptions) {
return options.name
}

/**
* Options for {@link doBarBetter}
*/
export interface DoBarBetterOptions {
name: string
number: number
}
3 changes: 2 additions & 1 deletion packages/starlight-typedoc/libs/starlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ export function getRelativeURL(url: string, baseUrl: string, pageUrl?: string):

const currentDirname = path.dirname(pageUrl ?? '')
const urlDirname = path.dirname(url)
const relativeUrl = currentDirname === urlDirname ? url : path.posix.relative(currentDirname, url)
const relativeUrl =
currentDirname === urlDirname ? url : path.posix.join(currentDirname, path.posix.relative(currentDirname, url))

const filePath = path.parse(relativeUrl)
const [, anchor] = filePath.base.split('#')
Expand Down
9 changes: 9 additions & 0 deletions packages/starlight-typedoc/tests/e2e/packages/content.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { test } from '../test'

test('should properly format links', async ({ docPage }) => {
docPage.usePackagesEntryPoints()

await docPage.goto('bar/functions/dobarbetter')

await docPage.content.getByRole('link', { exact: true, name: 'DoBarBetterOptions' }).click()
await docPage.page.waitForURL('**/api-packages-entrypoints/bar/interfaces/dobarbetteroptions/**')
})

test('should properly format links in block tag comments', async ({ docPage }) => {
docPage.usePackagesEntryPoints()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ test('should generate the proper items for for multiple entry points', async ({
{
label: 'bar',
items: [
{
label: 'Interfaces',
items: [{ name: 'DoBarBetterOptions' }],
},
{
label: 'Functions',
items: [{ name: 'doBar' }],
items: [{ name: 'doBar' }, { name: 'doBarBetter' }],
},
],
collapsed: true,
Expand Down

0 comments on commit 356b61e

Please sign in to comment.