waibu 1.1.15 → 1.1.17
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/lib/build-locals.js +8 -6
- package/package.json +1 -1
- package/plugin/factory.js +2 -1
package/lib/build-locals.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function buildHomesMenu (req) {
|
|
1
|
+
async 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,12 +10,14 @@ function buildHomesMenu (req) {
|
|
|
10
10
|
return orderBy(routes, ['title'])
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function buildPagesMenu (req) {
|
|
14
|
-
const { find, orderBy, merge } = this.lib._
|
|
13
|
+
async function buildPagesMenu (req) {
|
|
14
|
+
const { find, orderBy, merge, isString } = this.lib._
|
|
15
|
+
const { callHandler } = this.app.bajo
|
|
15
16
|
const all = [{ icon: 'house', href: '/', level: 1 }]
|
|
16
17
|
for (const ns of this.app.bajo.pluginNames) {
|
|
17
18
|
const items = []
|
|
18
|
-
|
|
19
|
+
let pages = this.app[ns].getConfig('waibuMpa.menuHandler', { defValue: [] })
|
|
20
|
+
if (isString(pages)) pages = await callHandler(pages, req)
|
|
19
21
|
if (pages.length === 0) continue
|
|
20
22
|
for (const page of pages) {
|
|
21
23
|
const existing = find(all, { title: page.title })
|
|
@@ -77,8 +79,8 @@ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
|
|
|
77
79
|
if (this.app.bajo.config.env === 'dev') console.log(params.error)
|
|
78
80
|
}
|
|
79
81
|
if (reply && req.session && req.flash && !opts.partial) _meta.flash = reply.flash()
|
|
80
|
-
set(params, 'menu.homes', buildHomesMenu.call(this, req))
|
|
81
|
-
set(params, 'menu.pages', buildPagesMenu.call(this, req))
|
|
82
|
+
set(params, 'menu.homes', await buildHomesMenu.call(this, req))
|
|
83
|
+
set(params, 'menu.pages', await buildPagesMenu.call(this, req))
|
|
82
84
|
const merged = merge({}, params, { _meta })
|
|
83
85
|
await runHook(`${this.name}:afterBuildLocals`, merged, req)
|
|
84
86
|
if (!isEmpty(routeOpts.ns)) await runHook(`${this.name}.${routeOpts.ns}:afterBuildLocals`, merged, req)
|
package/package.json
CHANGED