sitegen/framework/lib/sitegen.ts

91 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

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> | 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;
}
2025-06-09 21:13:51 -07:00
/**
* 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;
}
2025-08-14 20:35:33 -07:00
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<string, FontVariableAxis>;
layoutFeatures?: string[];
unicodes: FontRange | FontRange[];
/** Include [ext] to autofill 'woff2' */
asset: string;
}>;
}
export type FontVars = Record<string, FontVariableAxis>;
export type FontVariableAxis = number | [min: number, max: number];
export type FontRange = string | number | { start: number, end: number };
export const userData = render.userData<SitegenRender>(() => {
throw new Error("This function can only be used in a page (static or view)");
});
2025-06-09 21:13:51 -07:00
export interface SitegenRender {
2025-06-10 01:13:59 -07:00
scripts: Set<string>;
}
export function initRender(): SitegenRender {
return { scripts: new Set() };
}
/** Add a client-side script to the page. */
2025-06-10 01:13:59 -07:00
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 `<!doctype html><html lang=en><head>${head}${
inlineCss ? `<style>${inlineCss}</style>` : ""
}</head><body>${body}${
scripts ? `<script>${scripts}</script>` : ""
}</body></html>`;
}
import * as render from "#engine/render";
import type * as meta from "./meta.ts";
import type * as css from "../css.ts";