@adobe/helix-html-pipeline 5.6.3 → 5.7.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [5.7.1](https://github.com/adobe/helix-html-pipeline/compare/v5.7.0...v5.7.1) (2024-02-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * put <loc> on a single line ([#532](https://github.com/adobe/helix-html-pipeline/issues/532)) ([c8626eb](https://github.com/adobe/helix-html-pipeline/commit/c8626eb6a45819cdb8f6348752fb2883d9a2a7d9))
7
+
8
+ # [5.7.0](https://github.com/adobe/helix-html-pipeline/compare/v5.6.3...v5.7.0) (2024-02-05)
9
+
10
+
11
+ ### Features
12
+
13
+ * render sitemap from `sitemap.json` ([#527](https://github.com/adobe/helix-html-pipeline/issues/527)) ([414e36e](https://github.com/adobe/helix-html-pipeline/commit/414e36ea59e37a0f7c018db43aa2fe126172688f))
14
+
1
15
  ## [5.6.3](https://github.com/adobe/helix-html-pipeline/compare/v5.6.2...v5.6.3) (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": "5.6.3",
3
+ "version": "5.7.1",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -53,7 +53,8 @@
53
53
  "hast-util-to-html": "9.0.0",
54
54
  "hast-util-to-string": "3.0.0",
55
55
  "hastscript": "9.0.0",
56
- "jose": "5.2.0",
56
+ "jose": "5.2.1",
57
+ "lodash.escape": "4.0.1",
57
58
  "mdast-util-to-hast": "13.1.0",
58
59
  "mdast-util-to-string": "4.0.0",
59
60
  "mime": "4.0.1",
@@ -70,7 +71,7 @@
70
71
  "unist-util-visit-parents": "6.0.1"
71
72
  },
72
73
  "devDependencies": {
73
- "@adobe/eslint-config-helix": "2.0.5",
74
+ "@adobe/eslint-config-helix": "2.0.6",
74
75
  "@markedjs/html-differ": "4.0.2",
75
76
  "@semantic-release/changelog": "6.0.3",
76
77
  "@semantic-release/git": "10.0.1",
@@ -81,11 +82,11 @@
81
82
  "eslint-plugin-header": "3.1.1",
82
83
  "eslint-plugin-import": "2.29.1",
83
84
  "esmock": "2.6.3",
84
- "husky": "9.0.6",
85
+ "husky": "9.0.10",
85
86
  "js-yaml": "4.1.0",
86
87
  "jsdom": "24.0.0",
87
- "junit-report-builder": "3.1.0",
88
- "lint-staged": "15.2.0",
88
+ "junit-report-builder": "3.2.1",
89
+ "lint-staged": "15.2.1",
89
90
  "mocha": "10.2.0",
90
91
  "mocha-multi-reporters": "1.5.1",
91
92
  "mocha-suppress-logs": "0.4.1",
@@ -9,6 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
+ import escape from 'lodash.escape';
12
13
  import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
13
14
  import { authenticate, requireProject } from './steps/authenticate.js';
14
15
  import fetchConfig from './steps/fetch-config.js';
@@ -20,6 +21,47 @@ import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
20
21
  import { PipelineStatusError } from './PipelineStatusError.js';
21
22
  import { PipelineResponse } from './PipelineResponse.js';
22
23
 
24
+ async function generateSitemap(state, partition) {
25
+ const {
26
+ owner, repo, ref, contentBusId, s3Loader, log,
27
+ previewHost, liveHost, config: { host: prodCDN } = {},
28
+ } = state;
29
+ const ret = await s3Loader.getObject('helix-content-bus', `${contentBusId}/live/sitemap.json`);
30
+ if (ret.status !== 200) {
31
+ return ret;
32
+ }
33
+ let config;
34
+ try {
35
+ config = JSON.parse(ret.body);
36
+ } catch (e) {
37
+ log.info('failed to parse /sitemap.json', e);
38
+ throw new PipelineStatusError(404, `Failed to parse /sitemap.json: ${e.message}`);
39
+ }
40
+ const { data } = config;
41
+ if (!data || !Array.isArray(data)) {
42
+ throw new PipelineStatusError(404, 'Expected \'data\' array not found in /sitemap.json');
43
+ }
44
+ const host = partition === 'preview'
45
+ ? (previewHost || `${ref}--${repo}--${owner}.hlx.page`)
46
+ : (prodCDN || liveHost || `${ref}--${repo}--${owner}.hlx.live`);
47
+ const loc = ({ path, lastModified }) => ` <url>
48
+ <loc>https://${host}${escape(path)}</loc>
49
+ <lastmod>${new Date(lastModified * 1000).toISOString().substring(0, 10)}</lastmod>
50
+ </url>`;
51
+ const xml = [
52
+ '<?xml version="1.0" encoding="utf-8"?>',
53
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">',
54
+ ...data.map((record) => loc(record)),
55
+ '</urlset>',
56
+ ].join('\n');
57
+ return new PipelineResponse(xml, {
58
+ status: 200,
59
+ headers: {
60
+ 'content-type': 'application/xml; charset=utf-8',
61
+ },
62
+ });
63
+ }
64
+
23
65
  /**
24
66
  * Serves or renders the sitemap xml. The sitemap is always served from the preview content-bus
25
67
  * partition.
@@ -32,8 +74,9 @@ import { PipelineResponse } from './PipelineResponse.js';
32
74
  * @returns {PipelineResponse}
33
75
  */
34
76
  export async function sitemapPipe(state, req) {
35
- const { log } = state;
77
+ const { partition, log } = state;
36
78
  state.type = 'sitemap';
79
+
37
80
  // force loading from preview
38
81
  state.partition = 'preview';
39
82
 
@@ -78,7 +121,14 @@ export async function sitemapPipe(state, req) {
78
121
  if (res.error !== 401) {
79
122
  await authenticate(state, req, res);
80
123
  }
81
-
124
+ if (res.status === 404) {
125
+ const ret = await generateSitemap(state, partition);
126
+ if (ret.status === 200) {
127
+ res.status = 200;
128
+ delete res.error;
129
+ state.content.data = ret.body;
130
+ }
131
+ }
82
132
  if (res.error) {
83
133
  // if content loading produced an error, we're done.
84
134
  throw new PipelineStatusError(res.status, res.error);