export type ScriptId = string; export interface PageExports extends ViewExports { regenerate?: PageRegenerateOptions; } export interface ViewExports { default: render.Component; meta: meta.Meta | ((props: { ssr: true }) => Promise | meta.Meta); theme?: css.Theme; layout?: Layout; } export interface Layout { default: render.Component; theme?: css.Theme; // TODO: nested layout } export interface PageRegenerateOptions { tags?: string[]; seconds?: number; debounce?: number; } /** * A filesystem object associated with some ID, * such as a page's route to it's source file. */ export interface FileItem { id: string; file: string; } export interface Section { root: string; } export interface Font { name: string; /** * Specify either font name, file path, or URL to fetch it. * Private fonts do not have a URL and will fail to build if missing. */ sources: string[]; subsets: Array<{ vars?: Record; layoutFeatures?: string[]; unicodes: FontRange | FontRange[]; /** Include [ext] to autofill 'woff2' */ asset: string; }>; } export type FontVars = Record; export type FontVariableAxis = number | [min: number, max: number]; export type FontRange = string | number | { start: number, end: number }; export const userData = render.userData(() => { throw new Error("This function can only be used in a page (static or view)"); }); export interface SitegenRender { scripts: Set; } export function initRender(): SitegenRender { return { scripts: new Set() }; } /** Add a client-side script to the page. */ export function addScript(id: ScriptId | { value: ScriptId }) { userData.get().scripts.add(typeof id === "string" ? id : id.value); } export function wrapDocument({ body, head, inlineCss, scripts, }: { head: string; body: string; inlineCss: string; scripts: string; }) { return `${head}${ inlineCss ? `` : "" }${body}${ scripts ? `` : "" }`; } import * as render from "#engine/render"; import type * as meta from "./meta.ts"; import type * as css from "../css.ts";