page-context.ts
16 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.
Reference
interfaceBasePagePropsBase page props available for all pages.
Base page props available for all pages.
fnclearRenderContext(): voidClears the current render context. Called internally after page rendering.
interfaceFrontmatterSchemaSchema for frontmatter type generation.
Schema for frontmatter type generation.
fngenerateFrontmatterTypes(samples: Record<string, unknown>[], interfaceName = "PageFrontmatter"): stringGenerates TypeScript interface from frontmatter samples.
Generates TypeScript interface from frontmatter samples.
Parameters
-
samplesRecord[] -
paramunknown
Returns
string
fninferType(value: unknown): stringInfers TypeScript types from frontmatter values.
Infers TypeScript types from frontmatter values.
Parameters
-
valueunknown
Returns
string
typePageProps<T extends Record<string, unknown> = Record<string, unknown>> = BasePageProps & { /** Custom frontmatter fields */ frontmatter: T & Record<string, unknown>; }Extended page props with custom frontmatter.
Extended page props with custom frontmatter.
interfaceRenderContext<T extends Record<string, unknown> = Record<string, unknown>>Complete render context.
Complete render context.
fnsetRenderContext(ctx: RenderContext): voidSets the current render context. Called internally during page rendering.
Sets the current render context. Called internally during page rendering.
Parameters
-
ctxRenderContext
Returns
void
interfaceSiteConfigSite-wide configuration available in context.
Site-wide configuration available in context.
fnuseIsActive(path: string): booleanChecks if the given path is the current page.
Checks if the given path is the current page.
Parameters
-
pathstring
Returns
boolean
Examples
function NavLink({ href, children }) {
const isActive = useIsActive(href);
return <a href={href} class={isActive ? 'active' : ''}>{children}</a>;
}
fnusePageProps< T extends Record<string, unknown> = Record<string, unknown>, >(): PageProps<T>Gets the current page props.
Gets the current page props.
Returns
PageProps
The current page props
Examples
function PageTitle() {
const page = usePageProps();
return <h1>{page.title}</h1>;
}
fnuseRenderContext< T extends Record<string, unknown> = Record<string, unknown>, >(): RenderContext<T>Gets the full render context.
Gets the full render context.
Returns
RenderContext
The complete render context
Examples
function Layout({ children }) {
const ctx = useRenderContext();
return (
<html>
<head><title>{ctx.page.title} - {ctx.site.name}</title></head>
<body>{children}</body>
</html>
);
}
fnuseSiteConfig(): SiteConfigGets the site configuration.
Gets the site configuration.
Returns
SiteConfig
The site configuration
Examples
function SiteHeader() {
const site = useSiteConfig();
return <header>{site.name}</header>;
}