2025-06-06 23:38:02 -07:00
|
|
|
// 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;
|
|
|
|
}
|
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-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>`;
|
|
|
|
}
|
|
|
|
|
2025-08-02 19:22:07 -07:00
|
|
|
import * as render from "#engine/render";
|