waibu-mpa 1.2.14 → 1.2.15
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/index.js
CHANGED
|
@@ -18,7 +18,9 @@ async function parseAttrib ({ $, el, req } = {}) {
|
|
|
18
18
|
(['href', 'src', 'action'].includes(key) || key.includes('-href')) &&
|
|
19
19
|
!(val.slice(1, 3) === '%=' && val[val.length - 2] === '%')) {
|
|
20
20
|
el.attribs['o' + key] = val
|
|
21
|
-
|
|
21
|
+
try {
|
|
22
|
+
el.attribs[key] = routePath(val)
|
|
23
|
+
} catch (err) {}
|
|
22
24
|
}
|
|
23
25
|
// translate
|
|
24
26
|
if (key.slice(0, 2) === 't:') {
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
const omitted = ['css', 'style', 'scripts', 'ns', 'appTitle', 'title', 'fullTitle']
|
|
2
|
+
const names = ['description', 'keywords', 'robots', 'viewport', 'author', 'publisher',
|
|
3
|
+
'application-name', 'generator', 'referrer', 'theme-color', 'googlebot'
|
|
4
|
+
]
|
|
5
|
+
|
|
1
6
|
async function meta (options) {
|
|
2
7
|
const { runHook } = this.app.bajo
|
|
3
|
-
const { map, uniq, isArray, merge, kebabCase, keys, omit } = this.lib._
|
|
8
|
+
const { map, uniq, isArray, merge, kebabCase, keys, omit, get, isFunction } = this.lib._
|
|
9
|
+
const { sprintf } = this.lib
|
|
4
10
|
const { $, theme, req, locals } = options ?? {}
|
|
5
11
|
const { page = {} } = locals
|
|
6
12
|
let items = []
|
|
7
13
|
// meta
|
|
8
14
|
const links = ['preconnect', 'dnsPrefetch']
|
|
9
|
-
const omitted = ['css', 'style', 'scripts', 'ns', 'appTitle', 'title', 'fullTitle']
|
|
10
15
|
for (const attr of keys(omit(locals.page, [...links, ...omitted]))) {
|
|
11
16
|
if (!page[attr]) continue
|
|
17
|
+
if (!names.includes(attr)) continue
|
|
12
18
|
items.push({
|
|
13
19
|
name: attr,
|
|
14
20
|
content: isArray(page[attr]) ? page[attr].join(', ') : page[attr]
|
|
@@ -31,7 +37,13 @@ async function meta (options) {
|
|
|
31
37
|
return `<${tag} ${attrs} />`
|
|
32
38
|
})
|
|
33
39
|
$('head').prepend(uniq(items).join('\n'))
|
|
34
|
-
|
|
40
|
+
const mainTitle = get(this, 'app.main.config.waibu.title', 'Waibu App')
|
|
41
|
+
const formatter = get(this, 'app.waibu.pageTitleFormat', '%s : %s')
|
|
42
|
+
const title = page.fullTitle ?? page.title
|
|
43
|
+
let pageTitle
|
|
44
|
+
if (isFunction(formatter)) pageTitle = await formatter.call(this, title, mainTitle, locals)
|
|
45
|
+
else pageTitle = sprintf(formatter, title, mainTitle)
|
|
46
|
+
$('head').append(`<title>${pageTitle}</title>`)
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
export default meta
|
package/package.json
CHANGED