@adobe/helix-shared-config 8.0.0 → 8.1.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 +15 -0
- package/package.json +1 -1
- package/src/SitemapConfig.js +6 -1
- package/src/SitemapHandler.js +58 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [@adobe/helix-shared-config-v8.1.0](https://github.com/adobe/helix-shared/compare/@adobe/helix-shared-config-v8.0.0...@adobe/helix-shared-config-v8.1.0) (2022-06-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **sitemap:** create a separate context for each sitemap ([a27e80b](https://github.com/adobe/helix-shared/commit/a27e80be6a437d8e18071b5f0adcbcfbb52e5ab1))
|
|
7
|
+
* **sitemap:** use h1 ([25a4f97](https://github.com/adobe/helix-shared/commit/25a4f97229cd5f140c95f67200c002ecfba57662))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **sitemap:** allow resetting the fetch context ([df861d8](https://github.com/adobe/helix-shared/commit/df861d88c564b1a0cad2800b531a0444f586e728))
|
|
13
|
+
* **sitemap:** propagate resets ([41f77ab](https://github.com/adobe/helix-shared/commit/41f77abbd960073c2dff2575762efc4988783bc3))
|
|
14
|
+
* **sitemaps:** add `getContents()` and `getXML()` methods to retrieve sitemap content ([ee3fb07](https://github.com/adobe/helix-shared/commit/ee3fb07a170f016c15862623ca3b7e6debca283f))
|
|
15
|
+
|
|
1
16
|
# [@adobe/helix-shared-config-v8.0.0](https://github.com/adobe/helix-shared/compare/@adobe/helix-shared-config-v7.21.1...@adobe/helix-shared-config-v8.0.0) (2022-06-05)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
package/src/SitemapConfig.js
CHANGED
|
@@ -15,6 +15,7 @@ const { NamedMapHandler } = require('./NamedMapHandler');
|
|
|
15
15
|
const sitemapConfigSchema = require('./schemas/sitemapconfig.schema.json');
|
|
16
16
|
const sitemapSchema = require('./schemas/sitemap.schema.json');
|
|
17
17
|
const languageSchema = require('./schemas/sitemap-language.schema.json');
|
|
18
|
+
const { SitemapHandler } = require('./SitemapHandler.js');
|
|
18
19
|
|
|
19
20
|
class SitemapConfig extends SchemaDerivedConfig {
|
|
20
21
|
constructor() {
|
|
@@ -26,7 +27,7 @@ class SitemapConfig extends SchemaDerivedConfig {
|
|
|
26
27
|
'^/sitemaps/.*/languages/.*$': languageSchema,
|
|
27
28
|
},
|
|
28
29
|
handlers: {
|
|
29
|
-
'^/sitemaps$':
|
|
30
|
+
'^/sitemaps$': SitemapHandler(),
|
|
30
31
|
'^/sitemaps/.*/languages$': NamedMapHandler(),
|
|
31
32
|
},
|
|
32
33
|
});
|
|
@@ -42,6 +43,10 @@ class SitemapConfig extends SchemaDerivedConfig {
|
|
|
42
43
|
return this;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
reset() {
|
|
47
|
+
Object.values(this.sitemaps).forEach((sitemap) => sitemap.reset());
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
/**
|
|
46
51
|
* Adds a sitemap definition.
|
|
47
52
|
*
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
const fetchAPI = require('@adobe/helix-fetch');
|
|
13
|
+
const { NamedMapHandler } = require('./NamedMapHandler.js');
|
|
14
|
+
|
|
15
|
+
const wrap = (sitemap) => {
|
|
16
|
+
const context = process.env.HELIX_FETCH_FORCE_HTTP1
|
|
17
|
+
? fetchAPI.context({
|
|
18
|
+
alpnProtocols: [fetchAPI.ALPN_HTTP1_1],
|
|
19
|
+
})
|
|
20
|
+
: fetchAPI.context();
|
|
21
|
+
const { fetch } = context;
|
|
22
|
+
|
|
23
|
+
if (typeof sitemap === 'object') {
|
|
24
|
+
return {
|
|
25
|
+
...sitemap,
|
|
26
|
+
reset: () => {
|
|
27
|
+
context.reset();
|
|
28
|
+
},
|
|
29
|
+
getXML: async function getXML() {
|
|
30
|
+
const res = await fetch(new URL(this.destination, this.origin).href);
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
throw new Error(`Failed to fetch ${this.destination}`);
|
|
33
|
+
}
|
|
34
|
+
const xml = await res.text();
|
|
35
|
+
return xml;
|
|
36
|
+
},
|
|
37
|
+
getContents: async function getContents() {
|
|
38
|
+
const xml = await this.getXML();
|
|
39
|
+
return (xml.match(/<url>(.*?)<\/url>/gs) || []).reduce((acc, url) => {
|
|
40
|
+
const urlObj = new URL(url.match(/<loc>(.*?)<\/loc>/)[1], this.origin);
|
|
41
|
+
const lastmod = new Date(url.match(/<lastmod>(.*?)<\/lastmod>/)[1]);
|
|
42
|
+
acc.push({
|
|
43
|
+
url: urlObj,
|
|
44
|
+
lastmod,
|
|
45
|
+
});
|
|
46
|
+
return acc;
|
|
47
|
+
}, []);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return sitemap;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const SitemapHandler = (keyname = 'name') => ({
|
|
56
|
+
get: (target, prop) => wrap(NamedMapHandler(keyname).get(target, prop)),
|
|
57
|
+
});
|
|
58
|
+
exports.SitemapHandler = SitemapHandler;
|