feat: add json-ld

This commit is contained in:
2026-10-12 17:07:59 +05:00
parent 4bb4efd29b
commit 1981afbc64
7 changed files with 163 additions and 5 deletions
+21
View File
@@ -0,0 +1,21 @@
<script lang="ts">
interface Props {
data: Record<string, unknown> | Record<string, unknown>[];
}
let { data }: Props = $props();
// `<` is escaped so a value containing markup can never close the script tag
// early; U+2028/U+2029 are escaped because they break JS string literals.
const json = $derived(
JSON.stringify(data)
.replace(/</g, "\\u003c")
.replace(/[\u2028\u2029]/g, (c) =>
c === "\u2028" ? "\\u2028" : "\\u2029",
),
);
</script>
<!-- The closing tag is built from two parts: a literal `</script>` inside the
template would end the block the parser is reading. -->
<!-- eslint-disable-next-line svelte/no-at-html-tags -- json is escaped above, the only markup is this script wrapper -->
{@html `<script type="application/ld+json">${json}</` + "script>"}