2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-24 18:10:33 +03:00

fix: use document.title to update title on the client

This commit is contained in:
pimlie
2021-05-23 16:48:44 +02:00
parent 6593e9272d
commit 88d57e7199
3 changed files with 15 additions and 3 deletions
+1
View File
@@ -1,6 +1,7 @@
<!doctype html> <!doctype html>
<html {{ htmlAttrs }}> <html {{ htmlAttrs }}>
<head {{ headAttrs }}> <head {{ headAttrs }}>
<title>Hello</title>
{{ head }} {{ head }}
<link rel="stylesheet" href="/global.css"> <link rel="stylesheet" href="/global.css">
</head> </head>
+11 -3
View File
@@ -12,7 +12,8 @@ import type {
MetaRendered, MetaRendered,
MetaTagConfigKey, MetaTagConfigKey,
SlotScopeProperties, SlotScopeProperties,
TODO TODO,
ExcludesFalsy
} from './types' } from './types'
const cachedElements: { const cachedElements: {
@@ -77,6 +78,7 @@ export function renderGroup (
return renderTag(context, key, data[childKey], config as MetaConfigSectionTag, groupConfig) return renderTag(context, key, data[childKey], config as MetaConfigSectionTag, groupConfig)
}) })
.filter(Boolean as any as ExcludesFalsy)
.flat() .flat()
} }
@@ -86,7 +88,7 @@ export function renderTag (
data: TODO, data: TODO,
config: MetaConfigSectionTag = {}, config: MetaConfigSectionTag = {},
groupConfig?: MetaGroupConfig groupConfig?: MetaGroupConfig
): MetaRendered | MetaRenderedNode { ): MetaRendered | MetaRenderedNode | void {
// console.info('renderTag', key, data, config, groupConfig) // console.info('renderTag', key, data, config, groupConfig)
const contentAttributes = ['content', 'json', 'rawContent'] const contentAttributes = ['content', 'json', 'rawContent']
@@ -97,6 +99,7 @@ export function renderTag (
.map((child) => { .map((child) => {
return renderTag(context, key, child, config, groupConfig) return renderTag(context, key, child, config, groupConfig)
}) })
.filter(Boolean as any as ExcludesFalsy)
.flat() .flat()
} }
@@ -118,7 +121,7 @@ export function renderTag (
return data.map(({ vnode }) => vnode) return data.map(({ vnode }) => vnode)
} }
return data.vnode return data && data.vnode
}) })
} else { } else {
let i = 0 let i = 0
@@ -194,6 +197,11 @@ export function renderTag (
? `${groupConfig.tagNamespace}:${tag}` ? `${groupConfig.tagNamespace}:${tag}`
: tag : tag
if (finalTag === 'title' && !context.isSSR) {
document.title = content
return
}
// console.info('FINAL TAG', finalTag) // console.info('FINAL TAG', finalTag)
// console.log(' ATTRIBUTES', attributes) // console.log(' ATTRIBUTES', attributes)
// console.log(' CONTENT', content) // console.log(' CONTENT', content)
+3
View File
@@ -6,6 +6,9 @@ export * from './config'
export type Modify<T, R> = Omit<T, keyof R> & R; export type Modify<T, R> = Omit<T, keyof R> & R;
export type Truthy<T> = T extends undefined | void | null | false | 0 | '' ? never : T
export type ExcludesFalsy = <T>(x: T) => x is Truthy<T>
export type TODO = any export type TODO = any
/** /**