Skip to content

Commit

Permalink
fix: fixes link issues when using the Astro base option
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Dec 19, 2023
1 parent 383d59f commit 9959e2c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions example/astro.multiple-entrypoints.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from 'astro/config'
import starlightTypeDoc, { typeDocSidebarGroup } from 'starlight-typedoc'

export default defineConfig({
base: '/multiple-entrypoints/',
integrations: [
starlight({
plugins: [
Expand Down
4 changes: 2 additions & 2 deletions packages/starlight-typedoc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function starlightTypeDocPlugin(options: StarlightTypeDocOptions)
return {
name: 'starlight-typedoc-plugin',
hooks: {
async setup({ config, logger, updateConfig }) {
const { outputDirectory, reflections } = await generateTypeDoc(options, logger)
async setup({ astroConfig, config, logger, updateConfig }) {
const { outputDirectory, reflections } = await generateTypeDoc(options, astroConfig.base, logger)
const sidebar = getSidebarFromReflections(config.sidebar, options.sidebar, reflections, outputDirectory)

updateConfig({ sidebar })
Expand Down
6 changes: 4 additions & 2 deletions packages/starlight-typedoc/libs/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const markdownPluginConfig: TypeDocConfig = {
hidePageTitle: true,
}

export async function generateTypeDoc(options: StarlightTypeDocOptions, logger: AstroIntegrationLogger) {
export async function generateTypeDoc(options: StarlightTypeDocOptions, base: string, logger: AstroIntegrationLogger) {
const outputDirectory = options.output ?? 'api'

const app = await bootstrapApp(
Expand All @@ -42,6 +42,7 @@ export async function generateTypeDoc(options: StarlightTypeDocOptions, logger:
options.typeDoc,
outputDirectory,
options.pagination ?? false,
base,
logger,
)
const reflections = await app.convert()
Expand Down Expand Up @@ -69,6 +70,7 @@ async function bootstrapApp(
config: TypeDocConfig = {},
outputDirectory: string,
pagination: boolean,
base: string,
logger: AstroIntegrationLogger,
) {
const app = await Application.bootstrapWithPlugins({
Expand All @@ -87,7 +89,7 @@ async function bootstrapApp(
onRendererPageEnd(event, pagination)
})
app.options.addDeclaration({
defaultValue: `/${outputDirectory}${outputDirectory.endsWith('/') ? '' : '/'}`,
defaultValue: path.posix.join(base, `/${outputDirectory}${outputDirectory.endsWith('/') ? '' : '/'}`),
help: 'The starlight-typedoc output directory containing the generated documentation markdown files relative to the `src/content/docs/` directory.',
name: 'starlight-typedoc-output',
type: ParameterType.String,
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight-typedoc/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default defineConfig({
command: 'pnpm run dev:multiple-entrypoints',
cwd: '../../example',
reuseExistingServer: !process.env['CI'],
url: 'http://localhost:4322',
url: 'http://localhost:4322/multiple-entrypoints/',
},
],
})
2 changes: 1 addition & 1 deletion packages/starlight-typedoc/tests/e2e/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test('should properly format links with anchors for multiple entry points', asyn
.getByRole('link', { exact: true, name: 'constructor' })
.getAttribute('href')

expect(barConstructorLinkHref).toEqual('/api-multiple-entrypoints/bar/classes/bar/#constructors')
expect(barConstructorLinkHref).toEqual('/multiple-entrypoints/api-multiple-entrypoints/bar/classes/bar/#constructors')
})

test('should disable edit links', async ({ docPage }) => {
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 @@ -9,7 +9,7 @@ export class DocPage {

async goto(url: string) {
const baseUrl = `http://localhost:${this.#useMultipleEntryPoints ? 4322 : 4321}/${
this.#useMultipleEntryPoints ? 'api-multiple-entrypoints' : 'api'
this.#useMultipleEntryPoints ? 'multiple-entrypoints/api-multiple-entrypoints' : 'api'
}`

await this.page.goto(`${baseUrl}${url.startsWith('/') ? url : `/${url}`}${url.endsWith('/') ? '' : '/'}`)
Expand Down
1 change: 1 addition & 0 deletions packages/starlight-typedoc/tests/unit/typedoc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function generateTestTypeDoc(options: Parameters<typeof generateTypeDoc>[0]) {
...starlightTypeDocOptions,
...options,
},
'/',
{
info() {
// noop
Expand Down

0 comments on commit 9959e2c

Please sign in to comment.