Files
awesome-copilot/website/src/scripts/embedded-data.ts
T
Aaron Powell e65c8359b1 More website tweaks (#977)
* Some layout tweaks

* SSR resource listing pages

Render resource listing pages in Astro for first paint and hydrate client filtering/search behavior on top.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fixing font path

* removing feature plugin reference as we don't track that anymore

* button alignment

* rendering markdown

* Improve skills modal file browsing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Improving the layout of the search/filter section

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-12 11:48:54 +11:00

30 lines
929 B
TypeScript

const embeddedDataCache = new Map<string, unknown>();
export function getEmbeddedDataElementId(filename: string): string {
return `page-data-${filename.replace(/[^a-z0-9]+/gi, "-").toLowerCase()}`;
}
export function serializeEmbeddedData(data: unknown): string {
return JSON.stringify(data).replace(/</g, "\\u003c");
}
export function getEmbeddedData<T>(filename: string): T | null {
if (typeof document === "undefined") return null;
if (embeddedDataCache.has(filename)) {
return embeddedDataCache.get(filename) as T;
}
const element = document.getElementById(getEmbeddedDataElementId(filename));
if (!(element instanceof HTMLScriptElement)) return null;
try {
const data = JSON.parse(element.textContent || "null") as T;
embeddedDataCache.set(filename, data);
return data;
} catch (error) {
console.error(`Error parsing embedded data for ${filename}:`, error);
return null;
}
}