@adobe/helix-html-pipeline 6.3.4 → 6.4.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 +14 -0
- package/package.json +7 -6
- package/src/index.js +1 -0
- package/src/sitemap-pipe.js +135 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [6.4.1](https://github.com/adobe/helix-html-pipeline/compare/v6.4.0...v6.4.1) (2024-02-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* use correct partition ([#534](https://github.com/adobe/helix-html-pipeline/issues/534)) ([960256e](https://github.com/adobe/helix-html-pipeline/commit/960256eb6dd4045775ccf3203aa6b324558909d0))
|
|
7
|
+
|
|
8
|
+
# [6.4.0](https://github.com/adobe/helix-html-pipeline/compare/v6.3.4...v6.4.0) (2024-02-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* serve or render sitemap.xml ([#530](https://github.com/adobe/helix-html-pipeline/issues/530)) ([b72fe70](https://github.com/adobe/helix-html-pipeline/commit/b72fe70d1b7b22ce7c0ec7d9fefe72db2f472885)), closes [#472](https://github.com/adobe/helix-html-pipeline/issues/472)
|
|
14
|
+
|
|
1
15
|
## [6.3.4](https://github.com/adobe/helix-html-pipeline/compare/v6.3.3...v6.3.4) (2024-01-30)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-html-pipeline",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.1",
|
|
4
4
|
"description": "Helix HTML Pipeline",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"hast-util-to-html": "9.0.0",
|
|
55
55
|
"hast-util-to-string": "3.0.0",
|
|
56
56
|
"hastscript": "9.0.0",
|
|
57
|
-
"jose": "5.2.
|
|
57
|
+
"jose": "5.2.1",
|
|
58
|
+
"lodash.escape": "4.0.1",
|
|
58
59
|
"mdast-util-to-hast": "13.1.0",
|
|
59
60
|
"mdast-util-to-string": "4.0.0",
|
|
60
61
|
"mime": "4.0.1",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"unist-util-visit-parents": "6.0.1"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
|
-
"@adobe/eslint-config-helix": "2.0.
|
|
75
|
+
"@adobe/eslint-config-helix": "2.0.6",
|
|
75
76
|
"@markedjs/html-differ": "4.0.2",
|
|
76
77
|
"@semantic-release/changelog": "6.0.3",
|
|
77
78
|
"@semantic-release/git": "10.0.1",
|
|
@@ -82,11 +83,11 @@
|
|
|
82
83
|
"eslint-plugin-header": "3.1.1",
|
|
83
84
|
"eslint-plugin-import": "2.29.1",
|
|
84
85
|
"esmock": "2.6.3",
|
|
85
|
-
"husky": "9.0.
|
|
86
|
+
"husky": "9.0.10",
|
|
86
87
|
"js-yaml": "4.1.0",
|
|
87
88
|
"jsdom": "24.0.0",
|
|
88
|
-
"junit-report-builder": "3.1
|
|
89
|
-
"lint-staged": "15.2.
|
|
89
|
+
"junit-report-builder": "3.2.1",
|
|
90
|
+
"lint-staged": "15.2.1",
|
|
90
91
|
"mocha": "10.2.0",
|
|
91
92
|
"mocha-multi-reporters": "1.5.1",
|
|
92
93
|
"mocha-suppress-logs": "0.4.1",
|
package/src/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from './html-pipe.js';
|
|
|
13
13
|
export * from './json-pipe.js';
|
|
14
14
|
export * from './auth-pipe.js';
|
|
15
15
|
export * from './options-pipe.js';
|
|
16
|
+
export * from './sitemap-pipe.js';
|
|
16
17
|
export * from './PipelineContent.js';
|
|
17
18
|
export * from './PipelineRequest.js';
|
|
18
19
|
export * from './PipelineResponse.js';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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
|
+
import escape from 'lodash.escape';
|
|
13
|
+
import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
|
|
14
|
+
import fetchContent from './steps/fetch-content.js';
|
|
15
|
+
import renderCode from './steps/render-code.js';
|
|
16
|
+
import setXSurrogateKeyHeader from './steps/set-x-surrogate-key-header.js';
|
|
17
|
+
import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
|
|
18
|
+
import { PipelineStatusError } from './PipelineStatusError.js';
|
|
19
|
+
import { PipelineResponse } from './PipelineResponse.js';
|
|
20
|
+
import initConfig from './steps/init-config.js';
|
|
21
|
+
import { extractLastModified, updateLastModified } from './utils/last-modified.js';
|
|
22
|
+
|
|
23
|
+
async function generateSitemap(state) {
|
|
24
|
+
const {
|
|
25
|
+
owner, repo, ref, contentBusId, s3Loader, log, partition,
|
|
26
|
+
previewHost, liveHost, prodHost,
|
|
27
|
+
} = state;
|
|
28
|
+
const ret = await s3Loader.getObject('helix-content-bus', `${contentBusId}/live/sitemap.json`);
|
|
29
|
+
if (ret.status !== 200) {
|
|
30
|
+
return ret;
|
|
31
|
+
}
|
|
32
|
+
let config;
|
|
33
|
+
try {
|
|
34
|
+
config = JSON.parse(ret.body);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
log.info('failed to parse /sitemap.json', e);
|
|
37
|
+
throw new PipelineStatusError(404, `Failed to parse /sitemap.json: ${e.message}`);
|
|
38
|
+
}
|
|
39
|
+
const { data } = config;
|
|
40
|
+
if (!data || !Array.isArray(data)) {
|
|
41
|
+
throw new PipelineStatusError(404, 'Expected \'data\' array not found in /sitemap.json');
|
|
42
|
+
}
|
|
43
|
+
const host = partition === 'preview'
|
|
44
|
+
? (previewHost || `${ref}--${repo}--${owner}.hlx.page`)
|
|
45
|
+
: (prodHost || liveHost || `${ref}--${repo}--${owner}.hlx.live`);
|
|
46
|
+
const loc = ({ path, lastModified }) => ` <url>
|
|
47
|
+
<loc>https://${host}${escape(path)}</loc>
|
|
48
|
+
<lastmod>${new Date(lastModified * 1000).toISOString().substring(0, 10)}</lastmod>
|
|
49
|
+
</url>`;
|
|
50
|
+
const xml = [
|
|
51
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
52
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">',
|
|
53
|
+
...data.map((record) => loc(record)),
|
|
54
|
+
'</urlset>',
|
|
55
|
+
].join('\n');
|
|
56
|
+
return new PipelineResponse(xml, {
|
|
57
|
+
status: 200,
|
|
58
|
+
headers: {
|
|
59
|
+
'content-type': 'application/xml; charset=utf-8',
|
|
60
|
+
'last-modified': ret.headers.get('last-modified'),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Serves or renders the sitemap xml. The sitemap is always served from the preview content-bus
|
|
67
|
+
* partition.
|
|
68
|
+
*
|
|
69
|
+
* todo: currently only serves an existing sitemap.xml from the contentbus.
|
|
70
|
+
* generate sitemap on the fly based on the sitemap.json
|
|
71
|
+
*
|
|
72
|
+
* @param {PipelineState} state
|
|
73
|
+
* @param {PipelineRequest} req
|
|
74
|
+
* @returns {PipelineResponse}
|
|
75
|
+
*/
|
|
76
|
+
export async function sitemapPipe(state, req) {
|
|
77
|
+
const { log } = state;
|
|
78
|
+
state.type = 'sitemap';
|
|
79
|
+
|
|
80
|
+
if (state.info?.path !== '/sitemap.xml') {
|
|
81
|
+
// this should not happen as it would mean that the caller used the wrong route. so we respond
|
|
82
|
+
// with a 500 to indicate that something is wrong.
|
|
83
|
+
return new PipelineResponse('', {
|
|
84
|
+
status: 500,
|
|
85
|
+
headers: {
|
|
86
|
+
'x-error': 'invalid route',
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @type PipelineResponse */
|
|
92
|
+
const res = new PipelineResponse('', {
|
|
93
|
+
headers: {
|
|
94
|
+
'content-type': 'text/plain; charset=utf-8',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
await initConfig(state, req, res);
|
|
100
|
+
|
|
101
|
+
// fetch sitemap.xml
|
|
102
|
+
state.timer?.update('content-fetch');
|
|
103
|
+
await fetchContent(state, req, res);
|
|
104
|
+
if (res.status === 404) {
|
|
105
|
+
const ret = await generateSitemap(state);
|
|
106
|
+
if (ret.status === 200) {
|
|
107
|
+
res.status = 200;
|
|
108
|
+
updateLastModified(state, res, extractLastModified(ret.headers));
|
|
109
|
+
delete res.error;
|
|
110
|
+
state.content.data = ret.body;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (res.error) {
|
|
114
|
+
// if content loading produced an error, we're done.
|
|
115
|
+
throw new PipelineStatusError(res.status, res.error);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
state.timer?.update('serialize');
|
|
119
|
+
await renderCode(state, req, res);
|
|
120
|
+
await setCustomResponseHeaders(state, req, res);
|
|
121
|
+
await setXSurrogateKeyHeader(state, req, res);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
res.error = e.message;
|
|
124
|
+
res.status = e.code || 500;
|
|
125
|
+
|
|
126
|
+
const level = res.status >= 500 ? 'error' : 'info';
|
|
127
|
+
log[level](`pipeline status: ${res.status} ${res.error}`);
|
|
128
|
+
res.headers.set('x-error', cleanupHeaderValue(res.error));
|
|
129
|
+
if (res.status < 500) {
|
|
130
|
+
await setCustomResponseHeaders(state, req, res);
|
|
131
|
+
await setXSurrogateKeyHeader(state, req, res);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return res;
|
|
135
|
+
}
|