Skip to content

feat: format JSON-LD in response #798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/steps/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function createElement(name, ...attrs) {

function sanitizeJsonLd(jsonLd) {
const sanitizedJsonLd = jsonLd.replaceAll('<', '&#x3c;').replaceAll('>', '&#x3e;');
return JSON.stringify(JSON.parse(sanitizedJsonLd.trim()));
return JSON.stringify(JSON.parse(sanitizedJsonLd.trim()), null, 2);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/content/page-metadata-jsonld-global.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Global JSON LD Test">
<meta name="twitter:image" content="https://helix-pages.com/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<script type="application/ld+json">{"@context":"http://schema.org","@type":"Product","sku":"AA-BB-GLOBAL"}</script>
<script type="application/ld+json">{
"@context": "http://schema.org",
"@type": "Product",
"sku": "AA-BB-GLOBAL"
}</script>
<link id="favicon" rel="icon" type="image/svg+xml" href="/icons/spark.svg">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/scripts.js" type="module"></script>
Expand Down
12 changes: 11 additions & 1 deletion test/fixtures/content/page-metadata-jsonld-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Home | Helix Project Boilerplate">
<meta name="twitter:image" content="https://helix-pages.com/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<script type="application/ld+json">{"@context":"https://schema.org","@type":"Course","name":"Getting Started with AEM","description":"Setup your first project with AEM for Developers.","provider":{"@type":"Organization","name":"Adobe","sameAs":"http://www.adobe.com"}}</script>
<script type="application/ld+json">{
"@context": "https://schema.org",
"@type": "Course",
"name": "Getting Started with AEM",
"description": "Setup your first project with AEM for Developers.",
"provider": {
"@type": "Organization",
"name": "Adobe",
"sameAs": "http://www.adobe.com"
}
}</script>
<link id="favicon" rel="icon" type="image/svg+xml" href="/icons/spark.svg">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/scripts.js" type="module"></script>
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/content/page-metadata-jsonld-multi.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Home | Helix Project Boilerplate">
<meta name="twitter:image" content="https://helix-pages.com/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<script type="application/ld+json">{"@context":"http://schema.org","@type":"Product","sku":"FOO-BAR-12345"}</script>
<script type="application/ld+json">{
"@context": "http://schema.org",
"@type": "Product",
"sku": "FOO-BAR-12345"
}</script>
<link id="favicon" rel="icon" type="image/svg+xml" href="/icons/spark.svg">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/scripts.js" type="module"></script>
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/content/page-metadata-jsonld-xss.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Home | Helix Project Boilerplate">
<meta name="twitter:image" content="https://helix-pages.com/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<script type="application/ld+json">{"foo:":"&#x3c;/script&#x3e;alert('hello, world.')"}</script>
<script type="application/ld+json">{
"foo:": "&#x3c;/script&#x3e;alert('hello, world.')"
}</script>
<link id="favicon" rel="icon" type="image/svg+xml" href="/icons/spark.svg">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/scripts.js" type="module"></script>
Expand Down
7 changes: 6 additions & 1 deletion test/fixtures/content/page-metadata-jsonld.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Home | Helix Project Boilerplate">
<meta name="twitter:image" content="https://helix-pages.com/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<script type="application/ld+json">{"@context":"http://schema.org","@type":"Product","sku":"BPB-CMON-TABS"}</script>
<script type="application/ld+json">{
"@context": "http://schema.org",
"@type": "Product",
"sku": "BPB-CMON-TABS"
}
</script>
<link id="favicon" rel="icon" type="image/svg+xml" href="/icons/spark.svg">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/scripts.js" type="module"></script>
Expand Down
Loading