page-context.ts#
15 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.
Signature
export interface BasePagePropsMembers
Properties
| Name | Type | Description |
|---|---|---|
contributorsoptional |
Array<{ name: string; avatar?: string }> |
Unique git authors for this page |
descriptionoptional |
string |
Page description from frontmatter |
frontmatter |
Record<string, unknown> |
Raw frontmatter object |
html |
string |
Rendered HTML content |
lastUpdatedoptional |
number |
Last git commit timestamp in milliseconds |
layoutoptional |
string |
Layout name from frontmatter |
markdownSourceoptional |
string |
Published Markdown companion URL when ssg.markdownSource is on |
path |
string |
Source file path (relative to docs root) |
title |
string |
Page title from frontmatter or first heading |
toc |
TocEntry[] |
Table of contents entries |
url |
string |
Output URL path |
interfaceFrontmatterSchemaSchema for frontmatter type generation.
Schema for frontmatter type generation.
Signature
export interface FrontmatterSchemaMembers
Properties
| Name | Type | Description |
|---|---|---|
descriptionoptional |
string |
JSDoc description |
name |
string |
Field name |
optional |
boolean |
Whether the field is optional |
type |
string |
TypeScript type |
fngenerateFrontmatterTypes(samples: Record<string, unknown>[], interfaceName = "PageFrontmatter"): stringGenerates TypeScript interface from frontmatter samples.
Generates TypeScript interface from frontmatter samples.
Signature
export function generateFrontmatterTypes(samples: Record<string, unknown>[], interfaceName = "PageFrontmatter"): stringParameters
-
samplesRecord<string, unknown>[] -
interfaceNameunknownoptional · default: "PageFrontmatter"
Returns
string
fninferType(value: unknown): stringInfers TypeScript types from frontmatter values.
Infers TypeScript types from frontmatter values.
Signature
export function inferType(value: unknown): stringParameters
-
valueunknown
Returns
string
modulepage-contextPage Context for Static HTML Generation Provides a way to access page props (frontmatter, content, etc.) from theme com…
Page Context for Static HTML Generation
Provides a way to access page props (frontmatter, content, etc.) from theme components during static rendering.
Examples
// theme/Layout.tsx
import { usePageProps, PageProps } from '@ox-content/vite-plugin';
export function Layout({ children }: { children: JSX.Element }) {
const page = usePageProps<MyPageProps>();
return (
<html>
<head>
<title>{page.title}</title>
</head>
<body>
<header>{page.title}</header>
<main>{children}</main>
</body>
</html>
);
}typePageProps<T extends Record<string, unknown> = Record<string, unknown>> = BasePageProps & { frontmatter: T & Record<string, unknown> }Extended page props with custom frontmatter.
Extended page props with custom frontmatter.
Signature
export type PageProps<T extends Record<string, unknown> = Record<string, unknown>> = BasePageProps & { frontmatter: T & Record<string, unknown> }Members
Properties
| Name | Type | Description |
|---|---|---|
frontmatter |
T & Record<string, unknown> |
Custom frontmatter fields |
interfaceRenderContext<T extends Record<string, unknown> = Record<string, unknown>>Complete render context.
Complete render context.
Signature
export interface RenderContext<T extends Record<string, unknown> = Record<string, unknown>>Members
Properties
| Name | Type | Description |
|---|---|---|
page |
PageProps<T> |
Current page props |
site |
SiteConfig |
Site configuration |
interfaceSiteConfigSite-wide configuration available in context.
Site-wide configuration available in context.
Signature
export interface SiteConfigMembers
Properties
| Name | Type | Description |
|---|---|---|
base |
string |
Base URL path |
name |
string |
Site name |
nav |
NavGroup[] |
Navigation groups |
pages |
BasePageProps[] |
All pages in the site |
fnuseIsActive(path: string): booleanChecks if the given path is the current page.
Checks if the given path is the current page.
Signature
export function useIsActive(path: string): booleanParameters
-
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.
Signature
export function usePageProps<
T extends Record<string, unknown> = Record<string, unknown>,
>(): PageProps<T>Returns
PageProps<T>
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.
Signature
export function useRenderContext<
T extends Record<string, unknown> = Record<string, unknown>,
>(): RenderContext<T>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>
);
}fnuseSiteConfig(): SiteConfigGets the site configuration.
Gets the site configuration.
Signature
export function useSiteConfig(): SiteConfigReturns
SiteConfig
The site configuration
Examples
function SiteHeader() {
const site = useSiteConfig();
return <header>{site.name}</header>;
}