@adobe/helix-html-pipeline 5.11.13 → 5.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [5.12.1](https://github.com/adobe/helix-html-pipeline/compare/v5.12.0...v5.12.1) (2024-08-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * escape HTML characters in JSON LD ([#666](https://github.com/adobe/helix-html-pipeline/issues/666)) ([e669242](https://github.com/adobe/helix-html-pipeline/commit/e669242845a990dc8ffa8342b3eb09833db5d55b))
7
+
8
+ # [5.12.0](https://github.com/adobe/helix-html-pipeline/compare/v5.11.13...v5.12.0) (2024-07-31)
9
+
10
+
11
+ ### Features
12
+
13
+ * include json-ld from metadata ([#657](https://github.com/adobe/helix-html-pipeline/issues/657)) ([56c7d37](https://github.com/adobe/helix-html-pipeline/commit/56c7d376014583e8d6664886902ebc2400874bb2)), closes [#648](https://github.com/adobe/helix-html-pipeline/issues/648)
14
+
1
15
  ## [5.11.13](https://github.com/adobe/helix-html-pipeline/compare/v5.11.12...v5.11.13) (2024-07-15)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "5.11.13",
3
+ "version": "5.12.1",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -82,13 +82,13 @@
82
82
  "eslint-import-resolver-exports": "1.0.0-beta.5",
83
83
  "eslint-plugin-header": "3.1.1",
84
84
  "eslint-plugin-import": "2.29.1",
85
- "esmock": "2.6.6",
86
- "husky": "9.0.11",
85
+ "esmock": "2.6.7",
86
+ "husky": "9.1.4",
87
87
  "js-yaml": "4.1.0",
88
- "jsdom": "24.1.0",
89
- "junit-report-builder": "3.2.1",
90
- "lint-staged": "15.2.7",
91
- "mocha": "10.6.0",
88
+ "jsdom": "24.1.1",
89
+ "junit-report-builder": "5.0.0",
90
+ "lint-staged": "15.2.8",
91
+ "mocha": "10.7.3",
92
92
  "mocha-multi-reporters": "1.5.1",
93
93
  "mocha-suppress-logs": "0.5.1",
94
94
  "semantic-release": "24.0.0"
@@ -14,6 +14,7 @@
14
14
  import { h } from 'hastscript';
15
15
  import { unified } from 'unified';
16
16
  import rehypeParse from 'rehype-parse';
17
+ import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
17
18
 
18
19
  function appendElement($parent, $el) {
19
20
  if ($el) {
@@ -34,6 +35,11 @@ function createElement(name, ...attrs) {
34
35
  return h(name, properties);
35
36
  }
36
37
 
38
+ function sanitizeJsonLd(jsonLd) {
39
+ const sanitizedJsonLd = jsonLd.replaceAll('<', '&#x3c;').replaceAll('>', '&#x3e;');
40
+ return JSON.stringify(JSON.parse(sanitizedJsonLd.trim()));
41
+ }
42
+
37
43
  /**
38
44
  * @type PipelineStep
39
45
  * @param {PipelineState} state
@@ -59,7 +65,13 @@ export default async function render(state, req, res) {
59
65
  appendElement($head, createElement('link', 'rel', 'canonical', 'href', meta.canonical));
60
66
  }
61
67
 
68
+ let jsonLd;
62
69
  for (const [name, value] of Object.entries(meta.page)) {
70
+ if (name.toLowerCase() === 'json-ld') {
71
+ jsonLd = value;
72
+ // eslint-disable-next-line no-continue
73
+ continue;
74
+ }
63
75
  const attr = name.includes(':') && !name.startsWith('twitter:') ? 'property' : 'name';
64
76
  if (Array.isArray(value)) {
65
77
  for (const v of value) {
@@ -71,6 +83,19 @@ export default async function render(state, req, res) {
71
83
  }
72
84
  appendElement($head, createElement('link', 'rel', 'alternate', 'type', 'application/xml+atom', 'href', meta.feed, 'title', `${meta.title} feed`));
73
85
 
86
+ // inject json ld if valid
87
+ if (jsonLd) {
88
+ const props = { type: 'application/ld+json' };
89
+ try {
90
+ jsonLd = sanitizeJsonLd(jsonLd);
91
+ } catch (e) {
92
+ jsonLd = '';
93
+ props['data-error'] = `error in json-ld: ${cleanupHeaderValue(e.message)}`;
94
+ }
95
+ const script = h('script', props, jsonLd);
96
+ $head.children.push(script);
97
+ }
98
+
74
99
  // inject head.html
75
100
  const headHtml = state.helixConfig?.head?.data.html;
76
101
  if (headHtml) {