Ox Content

page-context.ts

Source

BasePageProps

interface

Base page props available for all pages.

Source


PageProps

type

Extended page props with custom frontmatter.

Source


SiteConfig

interface

Site-wide configuration available in context.

Source


NavGroup

interface

Navigation group.

Source


NavItem

interface

Navigation item.

Source


RenderContext

interface

Complete render context.

Source


setRenderContext

function

Sets the current render context. Called internally during page rendering.

Source

export function setRenderContext(ctx: RenderContext): void

Returns

void -


clearRenderContext

function

Clears the current render context. Called internally after page rendering.

Source

export function clearRenderContext(): void

Returns

void -


usePageProps

function

Gets the current page props.

Source

Returns

PageProps<T> - The current page props

Examples

function PageTitle() {
  const page = usePageProps();
  return <h1>{page.title}</h1>;
}

useSiteConfig

function

Gets the site configuration.

Source

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.

Source

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.

Source

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.

Source

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.

Source


inferType

function

Infers TypeScript types from frontmatter values.

Source

export function inferType(value: unknown): string

Returns

string -


generateFrontmatterTypes

function

Generates TypeScript interface from frontmatter samples.

Source

export function generateFrontmatterTypes(
  samples: Record<string, unknown>[],
  interfaceName = "PageFrontmatter"
  ): string

Returns

string -