File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 11---
22import { z } from " astro:schema" ;
33import { Badge } from " @astrojs/starlight/components" ;
4+ import { componentToString } from " ~/util/container" ;
45
56type Props = z .infer <typeof props >;
67
@@ -11,15 +12,17 @@ const props = z
1112 .strict ();
1213
1314const { 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 ()} />
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { experimental_AstroContainer } from "astro/container";
22import { getContainerRenderer } from "@astrojs/mdx" ;
33import { loadRenderers } from "astro:container" ;
44import { render , type CollectionEntry } from "astro:content" ;
5+ import type { AstroComponentFactory } from "astro/runtime/server/index.js" ;
56
67export 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+ }
You can’t perform that action at this time.
0 commit comments