Skip to content

Commit

Permalink
Fix usage of <StarlightPage> with a custom srcDir configuration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Jun 28, 2024
1 parent 0bcf93b commit dbfd3ee
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tidy-brooms-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes an issue when using the `<StarlightPage>` component in a custom page with a user-defined `srcDir` configuration.
12 changes: 12 additions & 0 deletions packages/starlight/__e2e__/collection-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect, testFactory } from './test-utils';

const test = await testFactory('./fixtures/custom-src-dir/');

test('builds a custom page using the `<StarlightPage>` component and a custom `srcDir`', async ({
page,
starlight,
}) => {
await starlight.goto('/custom');

await expect(page.getByText('Hello')).toBeVisible();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import starlight from '@astrojs/starlight';
import { defineConfig } from 'astro/config';

export default defineConfig({
srcDir: './www',
integrations: [
starlight({
title: 'Custom src directory',
}),
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@e2e/custom-src-dir",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/starlight": "workspace:*",
"astro": "^4.10.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineCollection } from 'astro:content';
import { docsSchema } from '@astrojs/starlight/schema';

export const collections = {
docs: defineCollection({ schema: docsSchema() }),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
---

<StarlightPage frontmatter={{ title: 'A custom page' }}>
<p>Hello</p>
</StarlightPage>
2 changes: 1 addition & 1 deletion packages/starlight/integrations/virtual-user-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function vitePluginStarlightUserConfig(
: 'export const logos = {};',
'virtual:starlight/collection-config': `let userCollections;
try {
userCollections = (await import('/src/content/config.ts')).collections;
userCollections = (await import('${new URL('./content/config.ts', srcDir).pathname}')).collections;
} catch {}
export const collections = userCollections;`,
...virtualComponentModules,
Expand Down
1 change: 1 addition & 0 deletions packages/starlight/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export default defineConfig({
},
],
testMatch: '__e2e__/*.test.ts',
workers: 1,
});
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbfd3ee

Please sign in to comment.