@adobe/helix-html-pipeline 3.7.6 → 3.7.8

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
+ ## [3.7.8](https://github.com/adobe/helix-html-pipeline/compare/v3.7.7...v3.7.8) (2022-12-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handle cloudflare url error gracefully (issue [#216](https://github.com/adobe/helix-html-pipeline/issues/216)) ([3d7e5fb](https://github.com/adobe/helix-html-pipeline/commit/3d7e5fb6dea06737c3d4f70b816c8bf70df8b2cd))
7
+
8
+ ## [3.7.7](https://github.com/adobe/helix-html-pipeline/compare/v3.7.6...v3.7.7) (2022-12-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove og:url meta tag if overridden with "" ([d605625](https://github.com/adobe/helix-html-pipeline/commit/d6056258ab5188362cd6afd94cd860a5dca6880a)), closes [#214](https://github.com/adobe/helix-html-pipeline/issues/214)
14
+
1
15
  ## [3.7.6](https://github.com/adobe/helix-html-pipeline/compare/v3.7.5...v3.7.6) (2022-11-29)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "3.7.6",
3
+ "version": "3.7.8",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -79,15 +79,15 @@
79
79
  "devDependencies": {
80
80
  "@adobe/eslint-config-helix": "1.3.2",
81
81
  "@markedjs/html-differ": "4.0.2",
82
- "@semantic-release/changelog": "6.0.1",
82
+ "@semantic-release/changelog": "6.0.2",
83
83
  "@semantic-release/git": "10.0.1",
84
84
  "@semantic-release/npm": "9.0.1",
85
85
  "c8": "7.12.0",
86
- "eslint": "8.28.0",
86
+ "eslint": "8.29.0",
87
87
  "eslint-import-resolver-exports": "1.0.0-beta.3",
88
88
  "eslint-plugin-header": "3.1.1",
89
89
  "eslint-plugin-import": "2.26.0",
90
- "esmock": "2.0.9",
90
+ "esmock": "2.1.0",
91
91
  "husky": "8.0.2",
92
92
  "js-yaml": "4.1.0",
93
93
  "jsdom": "20.0.3",
package/src/html-pipe.js CHANGED
@@ -144,7 +144,9 @@ export async function htmlPipe(state, req) {
144
144
 
145
145
  // turn any URL errors into a 400, since they are user input
146
146
  // see https://github.com/adobe/helix-pipeline-service/issues/346
147
- if (e.code === 'ERR_INVALID_URL') {
147
+ if (e.code === 'ERR_INVALID_URL' // node runtime
148
+ /* c8 ignore next */
149
+ || (e instanceof TypeError && e.message === 'Invalid URL string.')) { // cloudflare runtime
148
150
  res.status = 400;
149
151
  res.headers.set('x-error', cleanupHeaderValue(`invalid url: ${e.input}`));
150
152
  }
@@ -161,8 +161,6 @@ export default function extractMetaData(state, req) {
161
161
  getLocalMetadata(hast),
162
162
  );
163
163
 
164
- const IGNORED_CUSTOM_META = ['twitter:card'];
165
-
166
164
  // first process supported metadata properties
167
165
  [
168
166
  'title',
@@ -179,19 +177,12 @@ export default function extractMetaData(state, req) {
179
177
  delete metaConfig[name];
180
178
  }
181
179
  });
182
- if (Object.keys(metaConfig).length > 0) {
183
- // add rest to meta.custom
184
- meta.custom = Object.entries(metaConfig)
185
- .filter(([name]) => !IGNORED_CUSTOM_META.includes(name))
186
- .map(([name, value]) => ({
187
- name,
188
- value,
189
- property: name.includes(':'),
190
- }));
191
- }
192
-
193
180
  // default value for twitter:card (mandatory for rendering URLs as cards in tweets)
194
181
  meta['twitter:card'] = metaConfig['twitter:card'] || 'summary_large_image';
182
+ delete metaConfig['twitter:card'];
183
+
184
+ // add rest to meta.custom
185
+ meta.custom = metaConfig;
195
186
 
196
187
  if (meta.keywords) {
197
188
  meta.keywords = toList(meta.keywords).join(', ');
@@ -55,29 +55,51 @@ export default async function render(state, req, res) {
55
55
  ]);
56
56
 
57
57
  // add meta
58
+ // (this is so complicated to keep the order backward compatible to make the diff tests happy)
59
+ const metadata = {
60
+ 'og:title': meta.title,
61
+ 'og:description': meta.description,
62
+ 'og:url': meta.url,
63
+ 'og:image': meta.image,
64
+ 'og:image:secure_url': meta.image,
65
+ 'og:image:alt': meta.imageAlt,
66
+ 'og:updated_time': meta.modified_time,
67
+ 'article:tag': meta.tags || [],
68
+ 'article:section': meta.section,
69
+ 'article:published_time': meta.published_time,
70
+ 'article:modified_time': meta.modified_time,
71
+ 'twitter:card': meta['twitter:card'],
72
+ 'twitter:title': meta.title,
73
+ 'twitter:description': meta.description,
74
+ 'twitter:image': meta.image,
75
+ };
76
+ // remove meta with no values
77
+ for (const name of Object.keys(metadata)) {
78
+ if (!metadata[name]) {
79
+ delete metadata[name];
80
+ }
81
+ }
82
+ // append custom metadata
83
+ Object.assign(metadata, meta.custom);
84
+
85
+ // remove og:url with explicit removal marker
86
+ if (metadata['og:url'] === '""') {
87
+ delete metadata['og:url'];
88
+ }
89
+
58
90
  appendElement($head, createElement('link', 'rel', 'canonical', 'href', content.meta.canonical));
59
91
  appendElement($head, createElement('meta', 'name', 'description', 'content', content.meta.description));
60
92
  appendElement($head, createElement('meta', 'name', 'keywords', 'content', content.meta.keywords));
61
- appendElement($head, createElement('meta', 'property', 'og:title', 'content', content.meta.title));
62
- appendElement($head, createElement('meta', 'property', 'og:description', 'content', content.meta.description));
63
- appendElement($head, createElement('meta', 'property', 'og:url', 'content', content.meta.url));
64
- appendElement($head, createElement('meta', 'property', 'og:image', 'content', content.meta.image));
65
- appendElement($head, createElement('meta', 'property', 'og:image:secure_url', 'content', content.meta.image));
66
- appendElement($head, createElement('meta', 'property', 'og:image:alt', 'content', content.meta.imageAlt));
67
- appendElement($head, createElement('meta', 'property', 'og:updated_time', 'content', content.meta.modified_time));
68
- for (const tag of (meta.tags || [])) {
69
- appendElement($head, createElement('meta', 'property', 'article:tag', 'content', tag));
70
- }
71
- appendElement($head, createElement('meta', 'property', 'article:section', 'content', content.meta.section));
72
- appendElement($head, createElement('meta', 'property', 'article:published_time', 'content', content.meta.published_time));
73
- appendElement($head, createElement('meta', 'property', 'article:modified_time', 'content', content.meta.modified_time));
74
- appendElement($head, createElement('meta', 'name', 'twitter:card', 'content', content.meta['twitter:card']));
75
- appendElement($head, createElement('meta', 'name', 'twitter:title', 'content', content.meta.title));
76
- appendElement($head, createElement('meta', 'name', 'twitter:description', 'content', content.meta.description));
77
- appendElement($head, createElement('meta', 'name', 'twitter:image', 'content', content.meta.image));
78
93
 
79
- for (const custom of (meta.custom || [])) {
80
- appendElement($head, createElement('meta', custom.property ? 'property' : 'name', custom.name, 'content', custom.value));
94
+ for (const [name, value] of Object.entries(metadata)) {
95
+ const attr = name.includes(':') && !name.startsWith('twitter:') ? 'property' : 'name';
96
+ if (Array.isArray(value)) {
97
+ for (const v of value) {
98
+ appendElement($head, createElement('meta', attr, name, 'content', v));
99
+ }
100
+ } else {
101
+ appendElement($head, createElement('meta', attr, name, 'content', value));
102
+ }
81
103
  }
82
104
  appendElement($head, createElement('link', 'rel', 'alternate', 'type', 'application/xml+atom', 'href', meta.feed, 'title', `${meta.title} feed`));
83
105