@adobe/helix-html-pipeline 6.12.10 → 6.14.0

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
+ # [6.14.0](https://github.com/adobe/helix-html-pipeline/compare/v6.13.0...v6.14.0) (2024-08-01)
2
+
3
+
4
+ ### Features
5
+
6
+ * make json-ld metadata more robust ([#658](https://github.com/adobe/helix-html-pipeline/issues/658)) ([3d3e5dc](https://github.com/adobe/helix-html-pipeline/commit/3d3e5dc5e39a601a5f9b225d6409f2cfbdefc138))
7
+
8
+ # [6.13.0](https://github.com/adobe/helix-html-pipeline/compare/v6.12.10...v6.13.0) (2024-07-30)
9
+
10
+
11
+ ### Features
12
+
13
+ * include json-ld from metadata ([f1c9f3f](https://github.com/adobe/helix-html-pipeline/commit/f1c9f3f5b1980dec8dc257c4f1f36f75fb0a0a69)), closes [#648](https://github.com/adobe/helix-html-pipeline/issues/648)
14
+
1
15
  ## [6.12.10](https://github.com/adobe/helix-html-pipeline/compare/v6.12.9...v6.12.10) (2024-07-07)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "6.12.10",
3
+ "version": "6.14.0",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -80,13 +80,13 @@
80
80
  "eslint-import-resolver-exports": "1.0.0-beta.5",
81
81
  "eslint-plugin-header": "3.1.1",
82
82
  "eslint-plugin-import": "2.29.1",
83
- "esmock": "2.6.6",
84
- "husky": "9.0.11",
83
+ "esmock": "2.6.7",
84
+ "husky": "9.1.3",
85
85
  "js-yaml": "4.1.0",
86
- "jsdom": "24.1.0",
87
- "junit-report-builder": "3.2.1",
86
+ "jsdom": "24.1.1",
87
+ "junit-report-builder": "4.0.0",
88
88
  "lint-staged": "15.2.7",
89
- "mocha": "10.6.0",
89
+ "mocha": "10.7.0",
90
90
  "mocha-multi-reporters": "1.5.1",
91
91
  "mocha-suppress-logs": "0.5.1",
92
92
  "semantic-release": "24.0.0"
@@ -43,6 +43,12 @@ function readBlockConfig($block) {
43
43
  const [$name, $value] = $row.children;
44
44
  const name = toMetaName(toString($name));
45
45
  if (name) {
46
+ // special case for json-ld. don't apply any special formatting
47
+ if (name.toLowerCase() === 'json-ld') {
48
+ config[name] = toString($value).trim();
49
+ return;
50
+ }
51
+
46
52
  let value;
47
53
  const $firstChild = childNodes($value)[0];
48
54
  if ($firstChild) {
@@ -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,13 @@ function createElement(name, ...attrs) {
34
35
  return h(name, properties);
35
36
  }
36
37
 
38
+ function sanitizeJsonLd(jsonLd) {
39
+ if (jsonLd.toLowerCase().indexOf('</script>') >= 0) {
40
+ throw new Error('script tag not allowed');
41
+ }
42
+ return JSON.stringify(JSON.parse(jsonLd.trim()));
43
+ }
44
+
37
45
  /**
38
46
  * @type PipelineStep
39
47
  * @param {PipelineState} state
@@ -59,7 +67,13 @@ export default async function render(state, req, res) {
59
67
  appendElement($head, createElement('link', 'rel', 'canonical', 'href', meta.canonical));
60
68
  }
61
69
 
70
+ let jsonLd;
62
71
  for (const [name, value] of Object.entries(meta.page)) {
72
+ if (name.toLowerCase() === 'json-ld') {
73
+ jsonLd = value;
74
+ // eslint-disable-next-line no-continue
75
+ continue;
76
+ }
63
77
  const attr = name.includes(':') && !name.startsWith('twitter:') ? 'property' : 'name';
64
78
  if (Array.isArray(value)) {
65
79
  for (const v of value) {
@@ -71,6 +85,19 @@ export default async function render(state, req, res) {
71
85
  }
72
86
  appendElement($head, createElement('link', 'rel', 'alternate', 'type', 'application/xml+atom', 'href', meta.feed, 'title', `${meta.title} feed`));
73
87
 
88
+ // inject json ld if valid
89
+ if (jsonLd) {
90
+ const props = { type: 'application/ld+json' };
91
+ try {
92
+ jsonLd = sanitizeJsonLd(jsonLd);
93
+ } catch (e) {
94
+ jsonLd = '';
95
+ props['data-error'] = `error in json-ld: ${cleanupHeaderValue(e.message)}`;
96
+ }
97
+ const script = h('script', props, jsonLd);
98
+ $head.children.push(script);
99
+ }
100
+
74
101
  // inject head.html
75
102
  const headHtml = state.config?.head?.html;
76
103
  if (headHtml) {