it was weird. i pressed delete on a subfolder, i think one of the pages.off folders that i was using. and then, suddenly, nvim on windows 7 decided to delete every file in the directory. they weren't shred off the space time continuum, but just marked deleted. i had to pay $80 to get access to a software that could see them. bleh! just seeing all my work, a little over a week, was pretty heart shattering. but i remembered that long ago, a close friend said i could call them whenever i was feeling sad. i finally took them up on that offer. the first time i've ever called someone for emotional support. but it's ok. i got it back. and the site framework is better than ever. i'm gonna commit and push more often. the repo is private anyways.
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
// Import this file with 'import * as sg from "#sitegen";'
|
|
export type ScriptId = string;
|
|
|
|
export interface SitegenRender {
|
|
scripts: Set<ScriptId>;
|
|
}
|
|
|
|
export function initRender(): SitegenRender {
|
|
return {
|
|
scripts: new Set(),
|
|
};
|
|
}
|
|
|
|
export function getRender() {
|
|
return ssr.getUserData<SitegenRender>("sitegen", () => {
|
|
throw new Error(
|
|
"This function can only be used in a page (static or view)",
|
|
);
|
|
});
|
|
}
|
|
|
|
/** Add a client-side script to the page. */
|
|
export function addScript(id: ScriptId) {
|
|
const srcFile: string = util.getCallSites()
|
|
.find((site) => !site.scriptName.startsWith(import.meta.dirname))!
|
|
.scriptName;
|
|
const filePath = hot.resolveFrom(srcFile, id);
|
|
if (
|
|
!filePath.endsWith(".client.ts") &&
|
|
!filePath.endsWith(".client.tsx")
|
|
) {
|
|
throw new Error("addScript must be a .client.ts or .client.tsx");
|
|
}
|
|
getRender().scripts.add(filePath);
|
|
}
|
|
|
|
export function Script({ src }: { src: ScriptId }) {
|
|
if (!src) throw new Error("Missing 'src' attribute");
|
|
addScript(src);
|
|
return null;
|
|
}
|
|
|
|
export interface Section {
|
|
root: string;
|
|
}
|
|
|
|
import * as ssr from "./engine/ssr.ts";
|
|
import * as util from "node:util";
|
|
import * as hot from "./hot.ts";
|