sitegen/framework/lib/sitegen.ts

34 lines
814 B
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);
}
import * as render from "#engine/render";