Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing styles for dynamic routes rendering <StarlightPage> #2905

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/src/components/Test.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>I am purple</div>

<style>
div {
background-color: purple;
}
</style>
4 changes: 4 additions & 0 deletions docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ hero:
link: https://github.com/withastro/starlight
---

import Test from '../../components/Test.astro';

<Test />

import { CardGrid, Card } from '@astrojs/starlight/components';
import AboutAstro from '~/components/about-astro.astro';
import TestimonialGrid from '~/components/testimonial-grid.astro';
Expand Down
36 changes: 36 additions & 0 deletions docs/src/pages/[...dog].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';

/**
* Two conditions must be met for the issue to occur:
*
* - Use a rest parameter for the route
* - Render `<StarlightPage>`
*/

export function getStaticPaths() {
return [
{ params: { dog: 'clifford' } },
{ params: { dog: 'rover' } },
{ params: { dog: 'spot' } },
];
}
---

<StarlightPage frontmatter={{ title: 'My custom page' }}>
<p>This is a custom page</p>
</StarlightPage>

<!-- -->

<!-- <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test</title>
</head>
<body>
<p>This is a test</p>
</body>
</html> -->
2 changes: 1 addition & 1 deletion packages/starlight/routes/common.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import Page from '../components/Page.astro';
import { useRouteData } from '../utils/routing/data';
import { useRouteData } from '../utils/routing/use-data';
import { attachRouteDataAndRunMiddleware } from '../utils/routing/middleware';

await attachRouteDataAndRunMiddleware(Astro, await useRouteData(Astro));
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight/utils/routing/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function getSiteTitleHref(locale: string | undefined): string {
}

/** Generate a route object for Starlight’s 404 page. */
async function get404Route(locals: App.Locals): Promise<Route> {
export async function get404Route(locals: App.Locals): Promise<Route> {
const { lang = BuiltInDefaultLocale.lang, dir = BuiltInDefaultLocale.dir } =
config.defaultLocale || {};
let locale = config.defaultLocale?.locale;
Expand Down
14 changes: 14 additions & 0 deletions packages/starlight/utils/routing/use-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { APIContext } from 'astro';
import { getRouteBySlugParam } from '../routing';
import type { StarlightRouteData } from './types';
import { render } from 'astro:content';
import { generateRouteData, get404Route } from './data';

export async function useRouteData(context: APIContext): Promise<StarlightRouteData> {
const route =
('slug' in context.params && getRouteBySlugParam(context.params.slug)) ||
(await get404Route(context.locals));
const { Content, headings } = await render(route.entry);
const routeData = generateRouteData({ props: { ...route, headings }, url: context.url });
return { ...routeData, Content };
}
Loading