sitegen/framework/lib/sitegen.ts

52 lines
1.1 KiB
TypeScript
Raw Normal View History

// Import this file with 'import * as sg from "#sitegen";'
export type ScriptId = string;
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;
}
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);
}
2025-08-02 21:31:56 -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>`;
}
import * as render from "#engine/render";