Skip to content

Commit d426b7c

Browse files
authored
[Docs Site] Remove trailing whitespace from Type component (#20275)
* [Docs Site] Remove trailing whitespace from Type component * remove unused import
1 parent 8e07796 commit d426b7c

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/components/Type.astro

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import { z } from "astro:schema";
33
import { Badge } from "@astrojs/starlight/components";
4+
import { componentToString } from "~/util/container";
45
56
type Props = z.infer<typeof props>;
67
@@ -11,15 +12,17 @@ const props = z
1112
.strict();
1213
1314
const { text } = props.parse(Astro.props);
14-
---
1515
16-
<Badge
17-
text={text}
18-
style={{
16+
const html = await componentToString(Badge, {
17+
text,
18+
style: {
1919
color: "var(--sl-text-white)",
2020
backgroundColor: "var(--sl-color-gray-6)",
2121
borderColor: "var(--sl-color-gray-3)",
2222
fontSize: "0.7rem",
2323
fontWeight: "bold",
24-
}}
25-
/>
24+
},
25+
});
26+
---
27+
28+
<Fragment set:html={html.trim()} />

src/util/container.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { experimental_AstroContainer } from "astro/container";
22
import { getContainerRenderer } from "@astrojs/mdx";
33
import { loadRenderers } from "astro:container";
44
import { render, type CollectionEntry } from "astro:content";
5+
import type { AstroComponentFactory } from "astro/runtime/server/index.js";
56

67
export async function entryToString(
78
entry: CollectionEntry<"docs" | "changelog">,
@@ -25,3 +26,19 @@ export async function entryToString(
2526

2627
return html;
2728
}
29+
30+
export async function componentToString(
31+
component: AstroComponentFactory,
32+
props: any,
33+
) {
34+
const renderers = await loadRenderers([getContainerRenderer()]);
35+
const container = await experimental_AstroContainer.create({
36+
renderers,
37+
});
38+
39+
const html = await container.renderToString(component, {
40+
props,
41+
});
42+
43+
return html;
44+
}

0 commit comments

Comments
 (0)