@adobe/helix-html-pipeline 5.6.2 → 5.7.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,17 @@
1
+ # [5.7.0](https://github.com/adobe/helix-html-pipeline/compare/v5.6.3...v5.7.0) (2024-02-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * 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))
7
+
8
+ ## [5.6.3](https://github.com/adobe/helix-html-pipeline/compare/v5.6.2...v5.6.3) (2024-01-30)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update dependency @adobe/remark-gridtables to v3 ([#522](https://github.com/adobe/helix-html-pipeline/issues/522)) ([84c0dfc](https://github.com/adobe/helix-html-pipeline/commit/84c0dfc5a85cc73faa28ed7f09568c52de9dabfb))
14
+
1
15
  ## [5.6.2](https://github.com/adobe/helix-html-pipeline/compare/v5.6.1...v5.6.2) (2024-01-29)
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.2",
3
+ "version": "5.7.0",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -45,7 +45,7 @@
45
45
  "@adobe/helix-markdown-support": "7.1.0",
46
46
  "@adobe/helix-shared-utils": "3.0.1",
47
47
  "@adobe/mdast-util-gridtables": "4.0.0",
48
- "@adobe/remark-gridtables": "2.0.2",
48
+ "@adobe/remark-gridtables": "3.0.0",
49
49
  "cookie": "0.6.0",
50
50
  "github-slugger": "2.0.0",
51
51
  "hast-util-raw": "9.0.2",
@@ -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,49 @@ 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>
49
+ https://${host}${escape(path)}
50
+ </loc>
51
+ <lastmod>${new Date(lastModified * 1000).toISOString().substring(0, 10)}</lastmod>
52
+ </url>`;
53
+ const xml = [
54
+ '<?xml version="1.0" encoding="utf-8"?>',
55
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">',
56
+ ...data.map((record) => loc(record)),
57
+ '</urlset>',
58
+ ].join('\n');
59
+ return new PipelineResponse(xml, {
60
+ status: 200,
61
+ headers: {
62
+ 'content-type': 'application/xml; charset=utf-8',
63
+ },
64
+ });
65
+ }
66
+
23
67
  /**
24
68
  * Serves or renders the sitemap xml. The sitemap is always served from the preview content-bus
25
69
  * partition.
@@ -32,8 +76,9 @@ import { PipelineResponse } from './PipelineResponse.js';
32
76
  * @returns {PipelineResponse}
33
77
  */
34
78
  export async function sitemapPipe(state, req) {
35
- const { log } = state;
79
+ const { partition, log } = state;
36
80
  state.type = 'sitemap';
81
+
37
82
  // force loading from preview
38
83
  state.partition = 'preview';
39
84
 
@@ -78,7 +123,14 @@ export async function sitemapPipe(state, req) {
78
123
  if (res.error !== 401) {
79
124
  await authenticate(state, req, res);
80
125
  }
81
-
126
+ if (res.status === 404) {
127
+ const ret = await generateSitemap(state, partition);
128
+ if (ret.status === 200) {
129
+ res.status = 200;
130
+ delete res.error;
131
+ state.content.data = ret.body;
132
+ }
133
+ }
82
134
  if (res.error) {
83
135
  // if content loading produced an error, we're done.
84
136
  throw new PipelineStatusError(res.status, res.error);