@adobe/helix-html-pipeline 1.0.2 → 1.0.3
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
|
+
## [1.0.3](https://github.com/adobe/helix-html-pipeline/compare/v1.0.2...v1.0.3) (2022-03-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* fix canonical url and 404.html response, clean up meta ([5f3e999](https://github.com/adobe/helix-html-pipeline/commit/5f3e999a6e305fb6ecf7d2fefe3a38274a135433))
|
|
7
|
+
|
|
1
8
|
## [1.0.2](https://github.com/adobe/helix-html-pipeline/compare/v1.0.1...v1.0.2) (2022-03-08)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -11,17 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { resolve } from 'url';
|
|
13
13
|
import { getAbsoluteUrl, makeCanonicalHtmlUrl, optimizeImageURL } from './utils.js';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Converts all non-valid characters to `-`.
|
|
17
|
-
* @param {string} text input text
|
|
18
|
-
* @returns {string} the meta name
|
|
19
|
-
*/
|
|
20
|
-
function toMetaName(text) {
|
|
21
|
-
return text
|
|
22
|
-
.toLowerCase()
|
|
23
|
-
.replace(/[^0-9a-z:_]/gi, '-');
|
|
24
|
-
}
|
|
14
|
+
import { filterGlobalMetadata, toMetaName, ALLOWED_RESPONSE_HEADERS } from '../utils/metadata.js';
|
|
25
15
|
|
|
26
16
|
/**
|
|
27
17
|
* Cleans up comma-separated string lists and returns an array.
|
|
@@ -98,40 +88,6 @@ function readBlockConfig($block) {
|
|
|
98
88
|
return config;
|
|
99
89
|
}
|
|
100
90
|
|
|
101
|
-
function applyMetaRule(target, obj) {
|
|
102
|
-
Object.keys(obj).forEach((key) => {
|
|
103
|
-
const metaKey = toMetaName(key);
|
|
104
|
-
if (metaKey !== 'url' && obj[key]) {
|
|
105
|
-
target[metaKey] = obj[key];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function globToRegExp(glob) {
|
|
111
|
-
const reString = glob
|
|
112
|
-
.replace(/\*\*/g, '_')
|
|
113
|
-
.replace(/\*/g, '[0-9a-z-.]*')
|
|
114
|
-
.replace(/_/g, '.*');
|
|
115
|
-
return new RegExp(`^${reString}$`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function filterGlobalMetadata(metaRules, path) {
|
|
119
|
-
const metaConfig = {};
|
|
120
|
-
metaRules.forEach((rule) => {
|
|
121
|
-
const glob = rule.url || rule.URL || rule.Url;
|
|
122
|
-
if (glob && typeof glob === 'string' && /[0-9a-z-/*]/.test(glob)) {
|
|
123
|
-
if (glob.indexOf('*') >= 0) {
|
|
124
|
-
if (globToRegExp(glob).test(path)) {
|
|
125
|
-
applyMetaRule(metaConfig, rule);
|
|
126
|
-
}
|
|
127
|
-
} else if (glob === path) {
|
|
128
|
-
applyMetaRule(metaConfig, rule);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return metaConfig;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
91
|
/**
|
|
136
92
|
* Looks for metadata in the document.
|
|
137
93
|
* @param {HTMLDocument} document The document
|
|
@@ -196,11 +152,13 @@ export default function extractMetaData(state, req) {
|
|
|
196
152
|
});
|
|
197
153
|
if (Object.keys(metaConfig).length > 0) {
|
|
198
154
|
// add rest to meta.custom
|
|
199
|
-
meta.custom = Object.
|
|
200
|
-
name
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
155
|
+
meta.custom = Object.entries(metaConfig)
|
|
156
|
+
.filter(([name]) => !ALLOWED_RESPONSE_HEADERS.includes(name))
|
|
157
|
+
.map(([name, value]) => ({
|
|
158
|
+
name,
|
|
159
|
+
value,
|
|
160
|
+
property: name.includes(':'),
|
|
161
|
+
}));
|
|
204
162
|
}
|
|
205
163
|
|
|
206
164
|
if (meta.keywords) {
|
|
@@ -10,18 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
|
|
13
|
-
import { filterGlobalMetadata } from '
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Array of headers allowed in the metadata.json file.
|
|
17
|
-
*/
|
|
18
|
-
const allowList = [
|
|
19
|
-
'content-security-policy',
|
|
20
|
-
'content-security-policy-report-only',
|
|
21
|
-
'access-control-allow-origin',
|
|
22
|
-
'access-control-allow-methods',
|
|
23
|
-
'link',
|
|
24
|
-
];
|
|
13
|
+
import { filterGlobalMetadata, ALLOWED_RESPONSE_HEADERS } from '../utils/metadata.js';
|
|
25
14
|
|
|
26
15
|
/**
|
|
27
16
|
* Decorates the pipeline response object with the headers defined in metadata.json.
|
|
@@ -34,7 +23,7 @@ const allowList = [
|
|
|
34
23
|
export default function setCustomResponseHeaders(state, req, res) {
|
|
35
24
|
const meta = filterGlobalMetadata(state.metadata, state.info.path);
|
|
36
25
|
Object.entries(meta).forEach(([name, value]) => {
|
|
37
|
-
if (
|
|
26
|
+
if (ALLOWED_RESPONSE_HEADERS.includes(name)) {
|
|
38
27
|
res.headers.set(name, cleanupHeaderValue(value));
|
|
39
28
|
}
|
|
40
29
|
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Converts all non-valid characters to `-`.
|
|
14
|
+
* @param {string} text input text
|
|
15
|
+
* @returns {string} the meta name
|
|
16
|
+
*/
|
|
17
|
+
export function toMetaName(text) {
|
|
18
|
+
return text
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.replace(/[^0-9a-z:_]/gi, '-');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function applyMetaRule(target, obj) {
|
|
24
|
+
Object.keys(obj).forEach((key) => {
|
|
25
|
+
const metaKey = toMetaName(key);
|
|
26
|
+
if (metaKey !== 'url' && obj[key]) {
|
|
27
|
+
target[metaKey] = obj[key];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function globToRegExp(glob) {
|
|
33
|
+
const reString = glob
|
|
34
|
+
.replace(/\*\*/g, '_')
|
|
35
|
+
.replace(/\*/g, '[0-9a-z-.]*')
|
|
36
|
+
.replace(/_/g, '.*');
|
|
37
|
+
return new RegExp(`^${reString}$`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function filterGlobalMetadata(metaRules, path) {
|
|
41
|
+
const metaConfig = {};
|
|
42
|
+
metaRules.forEach((rule) => {
|
|
43
|
+
const glob = rule.url || rule.URL || rule.Url;
|
|
44
|
+
if (glob && typeof glob === 'string' && /[0-9a-z-/*]/.test(glob)) {
|
|
45
|
+
if (glob.indexOf('*') >= 0) {
|
|
46
|
+
if (globToRegExp(glob).test(path)) {
|
|
47
|
+
applyMetaRule(metaConfig, rule);
|
|
48
|
+
}
|
|
49
|
+
} else if (glob === path) {
|
|
50
|
+
applyMetaRule(metaConfig, rule);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return metaConfig;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Array of headers allowed in the metadata.json file.
|
|
59
|
+
*/
|
|
60
|
+
export const ALLOWED_RESPONSE_HEADERS = [
|
|
61
|
+
'content-security-policy',
|
|
62
|
+
'content-security-policy-report-only',
|
|
63
|
+
'access-control-allow-origin',
|
|
64
|
+
'access-control-allow-methods',
|
|
65
|
+
'link',
|
|
66
|
+
];
|