mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
feat: add json-ld
This commit is contained in:
@@ -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>"}
|
||||
Reference in New Issue
Block a user