@blocklet/meta 1.8.6 → 1.8.9

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,11 +46,15 @@ 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
  }
38
53
 
54
+ if (nav.role) {
55
+ item.role = nav.role;
56
+ }
57
+
39
58
  if (nav.items?.length) {
40
59
  const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
41
60
  if (list.length) {
@@ -70,15 +89,19 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
70
89
  item.icon = nav.icon;
71
90
  }
72
91
 
92
+ if (nav.role) {
93
+ item.role = nav.role;
94
+ }
95
+
73
96
  const childNavigation = get(child, 'meta.navigation', []);
74
97
  if (!childNavigation.length) {
75
98
  // child does not declares menu
76
- item.link = normalizePathPrefix(`${prefix}${child.mountPoint || '/'}`);
99
+ item.link = parseLink(child.mountPoint || '/', prefix);
77
100
  result.push(item);
78
101
  } else if (childNavigation.length === 1) {
79
102
  // child declares one menu
80
103
  item.title = nav.title || childNavigation[0].title || childTitle;
81
- item.link = normalizePathPrefix(`${prefix}${child.mountPoint}${childNavigation[0].link || '/'}`);
104
+ item.link = parseLink(childNavigation[0].link || '/', normalizePathPrefix(`${prefix}${child.mountPoint}`));
82
105
  result.push(item);
83
106
  } else {
84
107
  // child declares multiple menus
@@ -107,7 +130,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
107
130
 
108
131
  const markDuplicate = (navigation, urls = []) => {
109
132
  navigation.forEach((item) => {
110
- if (item.link && urls.includes(item.link)) {
133
+ if (item.link && urls.some((x) => isEqual(x, item.link))) {
111
134
  item.duplicate = true;
112
135
  }
113
136
  if (item.link) {
package/lib/schema.js CHANGED
@@ -237,9 +237,16 @@ 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(),
249
+ role: Joi.array().items(Joi.string().min(1)).single(),
243
250
  icon: Joi.string().min(1),
244
251
  });
245
252
 
package/lib/util.js CHANGED
@@ -129,7 +129,7 @@ const forEachBlocklet = (
129
129
 
130
130
  // parallel
131
131
  const tasks = inputTasks || [];
132
- tasks.push(cb(blocklet, { parent: _parent, root, level: _level, ancestors: _ancestors }));
132
+ tasks.push(cb(blocklet, { parent: _parent, root, level: _level, ancestors: _ancestors, id }));
133
133
  if (blocklet.children) {
134
134
  for (const child of blocklet.children) {
135
135
  forEachBlocklet(child, cb, {
@@ -139,7 +139,6 @@ const forEachBlocklet = (
139
139
  _level: _level + 1,
140
140
  _tasks: tasks,
141
141
  _ancestors: newAncestors,
142
- id,
143
142
  });
144
143
  }
145
144
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.6",
6
+ "version": "1.8.9",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,20 +18,20 @@
18
18
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.8.6",
22
- "@abtnode/util": "1.8.6",
23
- "@arcblock/did": "1.17.6",
24
- "@arcblock/did-ext": "1.17.6",
25
- "@arcblock/did-util": "1.17.6",
26
- "@arcblock/jwt": "1.17.6",
27
- "@ocap/asset": "1.17.6",
28
- "@ocap/mcrypto": "1.17.6",
29
- "@ocap/util": "1.17.6",
30
- "@ocap/wallet": "1.17.6",
21
+ "@abtnode/constant": "1.8.9",
22
+ "@abtnode/util": "1.8.9",
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
- "debug": "^4.3.3",
34
- "fs-extra": "^10.0.1",
33
+ "debug": "^4.3.4",
34
+ "fs-extra": "^10.1.0",
35
35
  "hosted-git-info": "3.0.8",
36
36
  "is-glob": "^4.0.3",
37
37
  "joi": "^17.6.0",
@@ -39,12 +39,12 @@
39
39
  "js-yaml": "^4.1.0",
40
40
  "json-stable-stringify": "^1.0.1",
41
41
  "lodash": "^4.17.21",
42
- "slugify": "^1.4.6",
42
+ "slugify": "^1.6.5",
43
43
  "url-join": "^4.0.1",
44
44
  "validate-npm-package-name": "^3.0.0"
45
45
  },
46
46
  "devDependencies": {
47
- "jest": "^27.4.5"
47
+ "jest": "^27.5.1"
48
48
  },
49
- "gitHead": "070dad4ce5e12c8961399788f9d206bf7d9d263f"
49
+ "gitHead": "1846a1f0bae2f870f3fe635b1f17ed06867d370d"
50
50
  }