waibu 1.1.16 → 1.1.18

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,21 +1,26 @@
1
- function buildHomesMenu (req) {
1
+ async function buildHomesMenu (req) {
2
+ const { callHandler } = this.app.bajo
2
3
  const { get, find, orderBy } = this.lib._
3
4
  const routes = []
4
5
  for (const ns of this.app.bajo.pluginNames) {
5
- const href = get(this, `app.${ns}.config.waibuMpa.home`)
6
- if (!href) continue
7
- const item = { href, ns, title: get(this, `app.${ns}.config.waibu.title`, this.app[ns].title) }
8
- if (!find(routes, { href })) routes.push(item)
6
+ let home = get(this, `app.${ns}.config.waibuMpa.home`)
7
+ const homeHandler = get(this, `app.${ns}.config.waibuMpa.homeHandler`)
8
+ if (homeHandler) home = await callHandler(homeHandler)
9
+ if (!home) continue
10
+ const item = { href: home, ns, title: get(this, `app.${ns}.config.waibu.title`, this.app[ns].title) }
11
+ if (!find(routes, { href: home })) routes.push(item)
9
12
  }
10
13
  return orderBy(routes, ['title'])
11
14
  }
12
15
 
13
- function buildPagesMenu (req) {
14
- const { find, orderBy, merge } = this.lib._
16
+ async function buildPagesMenu (req) {
17
+ const { find, orderBy, merge, isString } = this.lib._
18
+ const { callHandler } = this.app.bajo
15
19
  const all = [{ icon: 'house', href: '/', level: 1 }]
16
20
  for (const ns of this.app.bajo.pluginNames) {
17
21
  const items = []
18
- const pages = this.app[ns].getConfig('waibuMpa.pages', { defValue: [] })
22
+ let pages = this.app[ns].getConfig('waibuMpa.menuHandler', { defValue: [] })
23
+ if (isString(pages)) pages = await callHandler(pages, req)
19
24
  if (pages.length === 0) continue
20
25
  for (const page of pages) {
21
26
  const existing = find(all, { title: page.title })
@@ -77,8 +82,8 @@ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
77
82
  if (this.app.bajo.config.env === 'dev') console.log(params.error)
78
83
  }
79
84
  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))
85
+ set(params, 'menu.homes', await buildHomesMenu.call(this, req))
86
+ set(params, 'menu.pages', await buildPagesMenu.call(this, req))
82
87
  const merged = merge({}, params, { _meta })
83
88
  await runHook(`${this.name}:afterBuildLocals`, merged, req)
84
89
  if (!isEmpty(routeOpts.ns)) await runHook(`${this.name}.${routeOpts.ns}:afterBuildLocals`, merged, req)
package/lib/home.js CHANGED
@@ -1,9 +1,10 @@
1
1
  async function home () {
2
- const { defaultsDeep } = this.app.bajo
2
+ const { defaultsDeep, callHandler } = this.app.bajo
3
3
  const { isString, pick } = this.lib._
4
4
  const config = this.getConfig()
5
5
  if (config.home) {
6
6
  if (isString(config.home)) config.home = { path: config.home }
7
+ if (config.home.pathHandler) config.home.path = await callHandler(config.home.pathHandler)
7
8
  await this.instance.get('/', async function (req, reply) {
8
9
  if (!config.home.forward) return reply.redirectTo(config.home.path)
9
10
  const opts = defaultsDeep(pick(req, ['params', 'query']), pick(config.home, ['params', 'query']))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {