hezarfen_landing
Clone
https://git.tahinli.com/archive/hezarfen_landing.git
0 watching0 forksTypeScript581.6 KiB94b1804Burak Boduroğlu2 months ago15 commits
| 1 | import { useHead } from "@solidjs/meta"; |
| 2 | import { createUniqueId } from "solid-js"; |
| 3 | |
| 4 | /** |
| 5 | * Emits a `application/ld+json` block into the head. `@solidjs/meta` ships no |
| 6 | * `<Script>` of its own, but `useHead` takes any tag — `close` renders the |
| 7 | * children between an opening and closing tag, and escaping stays off so the |
| 8 | * JSON is not entity-encoded on the way out. |
| 9 | */ |
| 10 | export default function JsonLd(props: { data: object }) { |
| 11 | useHead({ |
| 12 | tag: "script", |
| 13 | props: { |
| 14 | type: "application/ld+json", |
| 15 | get children() { |
| 16 | // A literal `<` inside a string would let the payload close the script |
| 17 | // element early; JSON keeps its meaning with the escape in place. |
| 18 | return JSON.stringify(props.data).replace(/</g, "\\u003c"); |
| 19 | }, |
| 20 | }, |
| 21 | setting: { close: true }, |
| 22 | id: createUniqueId(), |
| 23 | }); |
| 24 | |
| 25 | return null; |
| 26 | } |