2025-06-06 23:38:02 -07:00
|
|
|
export type ScriptId = string;
|
|
|
|
|
2025-08-11 22:43:27 -07:00
|
|
|
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;
|
|
|
|
}
|
2025-08-02 19:22:07 -07:00
|
|
|
export interface Section {
|
|
|
|
root: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2025-06-06 23:38:02 -07:00
|
|
|
export interface SitegenRender {
|
2025-06-10 01:13:59 -07:00
|
|
|
scripts: Set<string>;
|
2025-06-06 23:38:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function initRender(): SitegenRender {
|
2025-08-02 19:22:07 -07:00
|
|
|
return { scripts: new Set() };
|
2025-07-08 23:10:41 -07:00
|
|
|
}
|
|
|
|
|
2025-06-06 23:38:02 -07:00
|
|
|
/** Add a client-side script to the page. */
|
2025-06-10 01:13:59 -07:00
|
|
|
export function addScript(id: ScriptId | { value: ScriptId }) {
|
2025-08-02 19:22:07 -07:00
|
|
|
userData.get().scripts.add(typeof id === "string" ? id : id.value);
|
2025-06-06 23:38:02 -07:00
|
|
|
}
|
|
|
|
|
2025-08-11 22:43:27 -07:00
|
|
|
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>`;
|
|
|
|
}
|
|
|
|
|
2025-08-02 19:22:07 -07:00
|
|
|
import * as render from "#engine/render";
|
2025-08-11 22:43:27 -07:00
|
|
|
import type * as meta from "./meta.ts";
|
|
|
|
import type * as css from "../css.ts";
|