waibu 1.1.12 → 1.1.13

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,4 +1,4 @@
1
- function buildHomesMenu () {
1
+ function buildHomesMenu (req) {
2
2
  const { get, find, orderBy } = this.lib._
3
3
  const routes = []
4
4
  for (const ns of this.app.bajo.pluginNames) {
@@ -10,13 +10,32 @@ function buildHomesMenu () {
10
10
  return orderBy(routes, ['title'])
11
11
  }
12
12
 
13
- function buildPagesMenu () {
14
- const { get, orderBy } = this.lib._
15
- const all = [{ icon: 'house', href: '/', title: 'home', level: 1 }]
13
+ function buildPagesMenu (req) {
14
+ const { orderBy } = this.lib._
15
+ const all = [{ icon: 'house', href: '/', level: 1 }]
16
16
  for (const ns of this.app.bajo.pluginNames) {
17
- const pages = get(this, `app.${ns}.config.waibuMpa.pages`, [])
17
+ const items = []
18
+ const pages = this.app[ns].getConfig('waibuMpa.pages', { defValue: [] })
18
19
  if (pages.length === 0) continue
19
- all.push(...pages)
20
+ for (const page of pages) {
21
+ if (page.visible === 'auth' && !req.user) continue
22
+ if (page.visible === 'anon' && req.user) continue
23
+ if (!page.children) {
24
+ items.push(page)
25
+ continue
26
+ }
27
+ const children = []
28
+ for (const child of page.children) {
29
+ if (child.visible === 'auth' && !req.user) continue
30
+ if (child.visible === 'anon' && req.user) continue
31
+ children.push(child)
32
+ }
33
+ if (children.length > 0) {
34
+ page.children = children
35
+ items.push(page)
36
+ }
37
+ }
38
+ all.push(...items)
20
39
  }
21
40
  return orderBy(all, ['level', 'title'])
22
41
  }
@@ -54,8 +73,8 @@ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
54
73
  if (this.app.bajo.config.env === 'dev') console.log(params.error)
55
74
  }
56
75
  if (reply && req.session && req.flash && !opts.partial) _meta.flash = reply.flash()
57
- set(params, 'menu.homes', buildHomesMenu.call(this))
58
- set(params, 'menu.pages', buildPagesMenu.call(this))
76
+ set(params, 'menu.homes', buildHomesMenu.call(this, req))
77
+ set(params, 'menu.pages', buildPagesMenu.call(this, req))
59
78
  const merged = merge({}, params, { _meta })
60
79
  await runHook(`${this.name}:afterBuildLocals`, merged, req)
61
80
  if (!isEmpty(routeOpts.ns)) await runHook(`${this.name}.${routeOpts.ns}:afterBuildLocals`, merged, req)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin/factory.js CHANGED
@@ -142,7 +142,8 @@ async function factory (pkgName) {
142
142
  })
143
143
  }
144
144
 
145
- escape = (text) => {
145
+ escape = (text = '') => {
146
+ if (typeof text !== 'string') return text
146
147
  const { forOwn } = this.lib._
147
148
  forOwn(this.escapeChars, (v, k) => {
148
149
  text = text.replaceAll(k, v)