mirror of
https://github.com/github/awesome-copilot.git
synced 2026-06-15 04:15:03 +00:00
e65c8359b1
* 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>
30 lines
929 B
TypeScript
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;
|
|
}
|
|
}
|