page-context.ts

Source

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.

View source

fnclearRenderContext(): voidClears the current render context. Called internally after page rendering.

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

View source

Returns

void
interfaceFrontmatterSchemaSchema for frontmatter type generation.

Schema for frontmatter type generation.

View source

fngenerateFrontmatterTypes(samples: Record<string, unknown>[], interfaceName = "PageFrontmatter"): stringGenerates TypeScript interface from frontmatter samples.

Generates TypeScript interface from frontmatter samples.

View source

Parameters

  • samples Record[]
  • param unknown

Returns

string
fninferType(value: unknown): stringInfers TypeScript types from frontmatter values.

Infers TypeScript types from frontmatter values.

View source

Parameters

  • value unknown

Returns

string
interfaceNavGroupNavigation group.

Navigation group.

View source

interfaceNavItemNavigation item.

Navigation item.

View source

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.

View source

interfaceRenderContext<T extends Record<string, unknown> = Record<string, unknown>>Complete render context.

Complete render context.

View source

fnsetRenderContext(ctx: RenderContext): voidSets the current render context. Called internally during page rendering.

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

View source

Parameters

  • ctx RenderContext

Returns

void
interfaceSiteConfigSite-wide configuration available in context.

Site-wide configuration available in context.

View source

fnuseIsActive(path: string): booleanChecks if the given path is the current page.

Checks if the given path is the current page.

View source

Parameters

  • path string

Returns

boolean

Examples

function NavLink({ href, children }) {
  const isActive = useIsActive(href);
  return <a href={href} class={isActive ? 'active' : ''}>{children}</a>;
}
fnuseNav(): NavGroup[]Gets the navigation groups.

Gets the navigation groups.

View source

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>
  );
}
fnusePageProps< T extends Record<string, unknown> = Record<string, unknown>, >(): PageProps<T>Gets the current page props.

Gets the current page props.

View source

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.

View source

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.

View source

Returns

SiteConfig

The site configuration

Examples

function SiteHeader() {
  const site = useSiteConfig();
  return <header>{site.name}</header>;
}