@adobe/helix-html-pipeline 6.21.6 → 6.22.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,10 @@
1
+ # [6.22.0](https://github.com/adobe/helix-html-pipeline/compare/v6.21.6...v6.22.0) (2025-03-20)
2
+
3
+
4
+ ### Features
5
+
6
+ * **metadata:** hreflang links ([#847](https://github.com/adobe/helix-html-pipeline/issues/847)) ([fe0ded5](https://github.com/adobe/helix-html-pipeline/commit/fe0ded545b69d8a1157cd5952725a9cc222dcbda))
7
+
1
8
  ## [6.21.6](https://github.com/adobe/helix-html-pipeline/compare/v6.21.5...v6.21.6) (2025-03-16)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "6.21.6",
3
+ "version": "6.22.0",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -85,7 +85,7 @@
85
85
  "js-yaml": "4.1.0",
86
86
  "jsdom": "26.0.0",
87
87
  "junit-report-builder": "5.1.1",
88
- "lint-staged": "15.4.3",
88
+ "lint-staged": "15.5.0",
89
89
  "mocha": "11.1.0",
90
90
  "mocha-multi-reporters": "1.5.1",
91
91
  "mocha-suppress-logs": "0.5.1",
@@ -17,6 +17,14 @@ import rehypeParse from 'rehype-parse';
17
17
  import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
18
18
  import { contentSecurityPolicyOnAST } from './csp.js';
19
19
 
20
+ const LANG_REGEX = /^[a-z]{2}(?:[-_][a-z]{2})?$/i;
21
+
22
+ function formatLang(lang) {
23
+ return lang
24
+ .replace('_', '-')
25
+ .toLowerCase();
26
+ }
27
+
20
28
  function appendElement($parent, $el) {
21
29
  if ($el) {
22
30
  $parent.children.push($el);
@@ -76,8 +84,19 @@ export default async function render(state, req, res) {
76
84
  continue;
77
85
  }
78
86
  if (name.toLowerCase() === 'html-lang') {
79
- if (/^[a-z]{2}([-_]{1}[a-z]{2})?$/i.test(value)) {
80
- htmlLang = value;
87
+ if (LANG_REGEX.test(value)) {
88
+ htmlLang = formatLang(value);
89
+ }
90
+ // eslint-disable-next-line no-continue
91
+ continue;
92
+ }
93
+ if (name.toLowerCase().startsWith('hreflang-')) {
94
+ const lang = name.substring(9);
95
+ if (LANG_REGEX.test(lang)) {
96
+ appendElement(
97
+ $head,
98
+ createElement('link', 'rel', 'alternate', 'hreflang', formatLang(lang), 'href', value),
99
+ );
81
100
  }
82
101
  // eslint-disable-next-line no-continue
83
102
  continue;