diff --git a/src/components/JsonLd.astro b/src/components/JsonLd.astro index 4866788..69c2a1e 100644 --- a/src/components/JsonLd.astro +++ b/src/components/JsonLd.astro @@ -1,4 +1,6 @@ --- +import { serializeJsonLd } from '../lib/json-ld.mjs'; + const { data } = Astro.props; --- -` or ` > done', + description: 'Line\u2028and paragraph\u2029separators', + keywords: ['', 'a&b'], + }; + const json = serializeJsonLd(data); + // With no `<` left, the browser can't find `&\u2028\u2029]/); + assert.match(json, /"Ends early \\u003c\/script\\u003e\\u003cb\\u003ex\\u003c\/b\\u003e \\u0026 \\u003c!-- comment/); + assert.match(json, /"Line\\u2028and paragraph\\u2029separators"/); + assert.deepEqual(JSON.parse(json), data); +}); + +test('JSON-LD without those characters is plain JSON.stringify', () => { + const data = { '@context': 'https://schema.org', name: 'meaningfool', sameAs: ['https://github.com/meaningfool'] }; + assert.equal(serializeJsonLd(data), JSON.stringify(data)); +});