page-context.ts
BasePageProps
interface
Base page props available for all pages.
PageProps
type
Extended page props with custom frontmatter.
SiteConfig
interface
Site-wide configuration available in context.
NavGroup
interface
Navigation group.
NavItem
interface
Navigation item.
RenderContext
interface
Complete render context.
setRenderContext
function
Sets the current render context. Called internally during page rendering.
export function setRenderContext(ctx: RenderContext): void
Returns
void -
clearRenderContext
function
Clears the current render context. Called internally after page rendering.
export function clearRenderContext(): void
Returns
void -
usePageProps
function
Gets the current page props.
Returns
PageProps<T> - The current page props
Examples
function PageTitle() {
const page = usePageProps();
return <h1>{page.title}</h1>;
}
useSiteConfig
function
Gets the site configuration.
export function useSiteConfig(): SiteConfig
Returns
SiteConfig - The site configuration
Examples
function SiteHeader() {
const site = useSiteConfig();
return <header>{site.name}</header>;
}
useRenderContext
function
Gets the full render context.
Returns
RenderContext<T> - 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>
);
}
useNav
function
Gets the navigation groups.
export function useNav(): NavGroup[]
Returns
NavGroup[] -
Examples
function Sidebar() {
const nav = useNav();
return (
<nav>
{each(nav, (group) => (
<div>
<h3>{group.title}</h3>
<ul>
{each(group.items, (item) => (
<li><a href={item.href}>{item.title}</a></li>
))}
</ul>
</div>
))}
</nav>
);
}
useIsActive
function
Checks if the given path is the current page.
export function useIsActive(path: string): boolean
Returns
boolean -
Examples
function NavLink({ href, children }) {
const isActive = useIsActive(href);
return <a href={href} class={isActive ? 'active' : ''}>{children}</a>;
}
FrontmatterSchema
interface
Schema for frontmatter type generation.
inferType
function
Infers TypeScript types from frontmatter values.
export function inferType(value: unknown): string
Returns
string -
generateFrontmatterTypes
function
Generates TypeScript interface from frontmatter samples.
export function generateFrontmatterTypes(
samples: Record<string, unknown>[],
interfaceName = "PageFrontmatter"
): string
Returns
string -