Skip to content

ssg.ts#

View Markdown

Source

31 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

31 symbols 18 functions 8 interfaces 4 variables 1 modules 44 parameters 42 members 18 returns 1 deprecated

Reference#

fnbuildNavItems(markdownFiles: string[], srcDir: string, base: string, extension: string): NavGroup[]Builds navigation items from markdown files, grouped by directory.

Builds navigation items from markdown files, grouped by directory.

Signature

export function buildNavItems(markdownFiles: string[], srcDir: string, base: string, extension: string): NavGroup[]

View source

Parameters

  • markdownFiles string[]
  • srcDir string
  • base string
  • extension string

Returns

NavGroup[]
fnbuildSsg(options: ResolvedOptions, root: string): Promise<SsgBuildResult>Builds all markdown files to static HTML.

Builds all markdown files to static HTML.

Signature

export async function buildSsg(options: ResolvedOptions, root: string): Promise<SsgBuildResult>

View source

Parameters

Returns

Promise<SsgBuildResult>
fnbuildThemeNavItems(sidebar: SidebarItem[], base: string, extension: string): NavGroup[]Builds navigation items from an explicit theme sidebar tree.

Builds navigation items from an explicit theme sidebar tree.

Signature

export function buildThemeNavItems(sidebar: SidebarItem[], base: string, extension: string): NavGroup[]

View source

Parameters

  • sidebar SidebarItem[]
  • base string
  • extension string

Returns

NavGroup[]
fncanonicalPageUrl(context: BuildSsgContext, urlPath: string): string | undefinedAbsolute URL of a page, or undefined when ssg.siteUrl is not set. Built the sam…

Absolute URL of a page, or undefined when ssg.siteUrl is not set.

Built the same way get_og_image_url builds the image URL next to it, so the canonical link and og:image always agree about where the page lives.

Signature

function canonicalPageUrl(context: BuildSsgContext, urlPath: string): string | undefined

View source

Parameters

  • context BuildSsgContext
  • urlPath string

Returns

string | undefined
fncollectMarkdownFiles(srcDir: string, extensions: readonly string[] = DEFAULT_MARKDOWN_EXTENSIONS): Promise<string[]>Collects all markdown files from the source directory.

Collects all markdown files from the source directory.

Signature

export async function collectMarkdownFiles(srcDir: string, extensions: readonly string[] = DEFAULT_MARKDOWN_EXTENSIONS): Promise<string[]>

View source

Parameters

  • srcDir string
  • extensions readonly string[]

    optional · default: DEFAULTMARKDOWNEXTENSIONS

Returns

Promise<string[]>
variableconst DEFAULT_HTML_TEMPLATE = "<!-- ox-content default HTML template is Rust-backed -->"Deprecated compatibility export for consumers that imported the former TypeScri…

Deprecated compatibility export for consumers that imported the former TypeScript SSG template. HTML generation is Rust-backed now.

Signature

export const DEFAULT_HTML_TEMPLATE = "<!-- ox-content default HTML template is Rust-backed -->"

View source

fnextractTitle(content: string, frontmatter: Record<string, unknown>): stringExtracts title from content or frontmatter.

Extracts title from content or frontmatter.

Signature

export function extractTitle(content: string, frontmatter: Record<string, unknown>): string

View source

Parameters

  • content string
  • frontmatter Record<string, unknown>

Returns

string
fnformatTitle(name: string): stringFormats a file/dir name as a title.

Formats a file/dir name as a title.

Signature

export function formatTitle(name: string): string

View source

Parameters

  • name string

Returns

string
fngenerateBareHtmlPage(content: string, title: string): stringGenerates bare HTML page (no navigation, no styles).

Generates bare HTML page (no navigation, no styles).

Signature

export function generateBareHtmlPage(content: string, title: string): string

View source

Parameters

  • content string
  • title string

Returns

string
fngenerateBarePage(page: SsgBarePage): stringGenerates a bare HTML page carrying head metadata and injected markup. Bare mod…

Generates a bare HTML page carrying head metadata and injected markup.

Bare mode leaves the shell to the consumer, but the metadata here is already computed for the themed page and cannot be recovered afterwards — the generated OG image in particular was only discoverable by guessing at the output directory. A page with none of it set renders exactly what bare mode emitted before, which keeps the no-JS size baseline honest.

Signature

export function generateBarePage(page: SsgBarePage): string

View source

Parameters

Returns

string
fngenerateHtmlPage(pageData: SsgPageData, navGroups: NavGroup[], siteName: string, base: string, ogImage?: string, theme?: ResolvedThemeConfig, locale?: string, availableLocales?: LocaleConfig[]): Promise<string>Generates HTML page with navigation using Rust NAPI bindings.

Generates HTML page with navigation using Rust NAPI bindings.

Signature

export async function generateHtmlPage(pageData: SsgPageData, navGroups: NavGroup[], siteName: string, base: string, ogImage?: string, theme?: ResolvedThemeConfig, locale?: string, availableLocales?: LocaleConfig[]): Promise<string>

View source

Parameters

Returns

Promise<string>
fngetHref(inputPath: string, srcDir: string, base: string, extension: string): stringConverts a markdown file path to an href.

Converts a markdown file path to an href.

Signature

export function getHref(inputPath: string, srcDir: string, base: string, extension: string): string

View source

Parameters

  • inputPath string
  • srcDir string
  • base string
  • extension string

Returns

string
fngetOutputPath(inputPath: string, srcDir: string, outDir: string, extension: string): stringConverts a markdown file path to its corresponding HTML output path.

Converts a markdown file path to its corresponding HTML output path.

Signature

export function getOutputPath(inputPath: string, srcDir: string, outDir: string, extension: string): string

View source

Parameters

  • inputPath string
  • srcDir string
  • outDir string
  • extension string

Returns

string
fngetUrlPath(inputPath: string, srcDir: string): stringConverts a markdown file path to a relative URL path.

Converts a markdown file path to a relative URL path.

Signature

export function getUrlPath(inputPath: string, srcDir: string): string

View source

Parameters

  • inputPath string
  • srcDir string

Returns

string
variableconst localeCodesCache = new WeakMap<LocaleConfig[], string[]>()Per-build cache for the locale-code list passed to getSsgPageLocale. The i18n.l…

Per-build cache for the locale-code list passed to getSsgPageLocale. The i18n.locales reference is stable across a build, so the .map to codes runs once instead of once per page.

Signature

const localeCodesCache = new WeakMap<LocaleConfig[], string[]>()

View source

interfaceNavGroupNavigation group for hierarchical navigation.

Navigation group for hierarchical navigation.

Signature

export interface NavGroup

View source

Members

Properties
NameTypeDescription
variableconst navGroupsForRustCache = new WeakMap<NavGroup[], RustNavGroup[]>()Per-build cache for the Rust-facing nav conversion. navGroups is the same conte…

Per-build cache for the Rust-facing nav conversion. navGroups is the same context.navItems reference for every page in a build, so the deep recursive copy below only needs to run once per build instead of once per page.

Signature

const navGroupsForRustCache = new WeakMap<NavGroup[], RustNavGroup[]>()

View source

fnresolveNavigationGroups(navigation: SsgNavigationGroup[] | undefined, base: string, extension: string): NavGroup[] | undefinedResolves manual navigation config to the format used by the built-in SSG render…

Resolves manual navigation config to the format used by the built-in SSG renderer.

Signature

export function resolveNavigationGroups(navigation: SsgNavigationGroup[] | undefined, base: string, extension: string): NavGroup[] | undefined

View source

Parameters

Returns

NavGroup[] | undefined
fnresolveSsgOptions(ssg: SsgOptions | boolean | undefined): ResolvedSsgOptionsResolves SSG options with defaults.

Resolves SSG options with defaults.

Signature

export function resolveSsgOptions(ssg: SsgOptions | boolean | undefined): ResolvedSsgOptions

View source

Parameters

Returns

ResolvedSsgOptions
interfaceRustLocaleRust-facing locale shape.

Rust-facing locale shape.

Signature

interface RustLocale

View source

Members

Properties
NameTypeDescription
code string
dir string
name string
variableconst rustLocalesCache = new WeakMap<LocaleConfig[], RustLocale[]>()Per-build cache for the Rust-facing locale list. i18n.locales is the same refer…

Per-build cache for the Rust-facing locale list. i18n.locales is the same reference for every page in a build, so this mapping (and the ?? "ltr" default) only runs once per build instead of once per page.

Signature

const rustLocalesCache = new WeakMap<LocaleConfig[], RustLocale[]>()

View source

interfaceRustNavGroupNAPI-facing nav group shape produced from a NavGroup.

NAPI-facing nav group shape produced from a [NavGroup].

Signature

interface RustNavGroup

View source

Members

Properties
NameTypeDescription
collapsedoptional boolean
items SsgNavItem[]
stickyCollapsedoptional boolean
title string
fnshouldGenerateOgImages(options: ResolvedOptions): booleanWhether this build emits one Open Graph image per page. ssg.bare deliberately d…

Whether this build emits one Open Graph image per page.

ssg.bare deliberately does not turn this off. Bare mode only drops the generated page shell, and bringing your own shell is exactly the case where per-page OG images are still wanted — the images are written to the output tree and the consumer injects the <meta> tags itself. Nothing in the bare HTML references them, because bare output has no <head> to put them in.

Signature

export function shouldGenerateOgImages(options: ResolvedOptions): boolean

View source

Parameters

Returns

boolean
modulessgSSG (Static Site Generation) module for ox-content

SSG (Static Site Generation) module for ox-content

View source

interfaceSsgBarePageHead metadata and injected markup for a bare page.

Head metadata and injected markup for a bare page.

Signature

export interface SsgBarePage

View source

Members

Properties
NameTypeDescription
bodyEndoptional string
bodyStartoptional string
canonicalUrloptional string
content string
descriptionoptional string
diroptional string
headoptional string
langoptional string
ogImageoptional string
siteNameoptional string
title string
interfaceSsgBuildResultResult of an SSG build.

Result of an SSG build.

Signature

export interface SsgBuildResult

View source

Members

Properties
NameTypeDescription
errors string[]
Per-page failures that did not abort the build.
files string[]
Every file written, HTML pages and generated OG images alike.
ogImages Record<string, string>
Generated OG image URL per source file, keyed by absolute input path.

Bare mode renders these into the page itself, but a consumer
post-processing the output had no way to find them short of probing the
output directory for og-image.png.
interfaceSsgEntryPageConfigEntry page configuration for SSG (passed to Rust).

Entry page configuration for SSG (passed to Rust).

Signature

export interface SsgEntryPageConfig

View source

Members

Properties
NameTypeDescription
featuresoptional FeatureConfig[]
herooptional HeroConfig
interfaceSsgNavItemNavigation item for SSG.

Navigation item for SSG.

Signature

export interface SsgNavItem

View source

Members

Properties
NameTypeDescription
childrenoptional SsgNavItem[]
collapsedoptional boolean
href string
path string
stickyCollapsedoptional boolean
title string
interfaceSsgPageDataPage data for SSG.

Page data for SSG.

Signature

export interface SsgPageData

View source

Members

Properties
NameTypeDescription
content string
descriptionoptional string
entryPageoptional SsgEntryPageConfig
Entry page configuration (if layout: entry)
frontmatter Record<string, unknown>
href string
lastUpdatedoptional number
path string
title string
toc TocEntry[]
fntoRustTocEntry(entry: TocEntry): TocEntryConverts a TocEntry tree into the plain shape the Rust binding expects. Hoisted…

Converts a TocEntry tree into the plain shape the Rust binding expects. Hoisted to module scope so it isn't reallocated for every page; the per-page .map over pageData.toc still runs since the TOC is page-specific.

Signature

function toRustTocEntry(entry: TocEntry): TocEntry

View source

Parameters

Returns

TocEntry
fntoThemePageData(pageResult: PageProcessResult): ThemePageDataMaps an internal page result onto the theme renderer's page shape.

Maps an internal page result onto the theme renderer's page shape.

Signature

function toThemePageData(pageResult: PageProcessResult): ThemePageData

View source

Parameters

  • pageResult PageProcessResult

Returns

ThemePageData

Last updated: