@blocklet/meta 1.8.7 → 1.8.10

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.
@@ -1,6 +1,21 @@
1
1
  const get = require('lodash/get');
2
+ const isEqual = require('lodash/isEqual');
2
3
  const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
3
4
 
5
+ const parseLinkString = (link, prefix = '') =>
6
+ link.startsWith('/') ? normalizePathPrefix(`${prefix}${link || '/'}`) : link;
7
+
8
+ const parseLink = (input, prefix) => {
9
+ if (Object.prototype.toString.call(input) === '[object Object]') {
10
+ return Object.entries(input).reduce((o, [key, value]) => {
11
+ o[key] = parseLinkString(value, prefix);
12
+ return o;
13
+ }, {});
14
+ }
15
+
16
+ return parseLinkString(input, prefix);
17
+ };
18
+
4
19
  /**
5
20
  * @param {*} navigation src
6
21
  * @param {*} blocklet
@@ -31,7 +46,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
31
46
  }
32
47
 
33
48
  if (nav.link) {
34
- item.link = nav.link.startsWith('/') ? normalizePathPrefix(`${prefix}${nav.link || '/'}`) : nav.link;
49
+ item.link = parseLink(nav.link, prefix);
35
50
  } else {
36
51
  item.link = '';
37
52
  }
@@ -81,12 +96,12 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
81
96
  const childNavigation = get(child, 'meta.navigation', []);
82
97
  if (!childNavigation.length) {
83
98
  // child does not declares menu
84
- item.link = normalizePathPrefix(`${prefix}${child.mountPoint || '/'}`);
99
+ item.link = parseLink(child.mountPoint || '/', prefix);
85
100
  result.push(item);
86
101
  } else if (childNavigation.length === 1) {
87
102
  // child declares one menu
88
103
  item.title = nav.title || childNavigation[0].title || childTitle;
89
- item.link = normalizePathPrefix(`${prefix}${child.mountPoint}${childNavigation[0].link || '/'}`);
104
+ item.link = parseLink(childNavigation[0].link || '/', normalizePathPrefix(`${prefix}${child.mountPoint}`));
90
105
  result.push(item);
91
106
  } else {
92
107
  // child declares multiple menus
@@ -115,7 +130,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
115
130
 
116
131
  const markDuplicate = (navigation, urls = []) => {
117
132
  navigation.forEach((item) => {
118
- if (item.link && urls.includes(item.link)) {
133
+ if (item.link && urls.some((x) => isEqual(x, item.link))) {
119
134
  item.duplicate = true;
120
135
  }
121
136
  if (item.link) {
package/lib/schema.js CHANGED
@@ -237,7 +237,13 @@ const navigationItemSchema = Joi.object({
237
237
  }).min(1)
238
238
  )
239
239
  .required(),
240
- link: Joi.string().min(1),
240
+ link: Joi.alternatives().try(
241
+ Joi.string(),
242
+ Joi.object({
243
+ zh: Joi.string(),
244
+ en: Joi.string(),
245
+ }).min(1)
246
+ ),
241
247
  child: Joi.string().min(1), // child name or child did
242
248
  section: Joi.array().items(Joi.string().min(1)).single(),
243
249
  role: Joi.array().items(Joi.string().min(1)).single(),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.7",
6
+ "version": "1.8.10",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,16 +18,16 @@
18
18
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.8.7",
22
- "@abtnode/util": "1.8.7",
23
- "@arcblock/did": "1.17.10",
24
- "@arcblock/did-ext": "1.17.10",
25
- "@arcblock/did-util": "1.17.10",
26
- "@arcblock/jwt": "1.17.10",
27
- "@ocap/asset": "1.17.10",
28
- "@ocap/mcrypto": "1.17.10",
29
- "@ocap/util": "1.17.10",
30
- "@ocap/wallet": "1.17.10",
21
+ "@abtnode/constant": "1.8.10",
22
+ "@abtnode/util": "1.8.10",
23
+ "@arcblock/did": "1.17.11",
24
+ "@arcblock/did-ext": "1.17.11",
25
+ "@arcblock/did-util": "1.17.11",
26
+ "@arcblock/jwt": "1.17.11",
27
+ "@ocap/asset": "1.17.11",
28
+ "@ocap/mcrypto": "1.17.11",
29
+ "@ocap/util": "1.17.11",
30
+ "@ocap/wallet": "1.17.11",
31
31
  "ajv": "^8.11.0",
32
32
  "cjk-length": "^1.0.0",
33
33
  "debug": "^4.3.4",
@@ -46,5 +46,5 @@
46
46
  "devDependencies": {
47
47
  "jest": "^27.5.1"
48
48
  },
49
- "gitHead": "9807ea28b3ae634f5806c875774ac3b7e38502a1"
49
+ "gitHead": "84f655bd7b8d55fde2656fac8671faad3c3bde28"
50
50
  }