2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-20 04:20:34 +03:00

logically group modules into folders

This commit is contained in:
Declan de Wet
2016-11-02 23:11:28 +02:00
parent a3c17f1c14
commit 701bedc170
13 changed files with 46 additions and 43 deletions
+35
View File
@@ -0,0 +1,35 @@
import getComponentOption from './getComponentOption'
/**
* Returns the correct meta info for the given component
* (child components will overwrite parent meta info)
*
* @param {Object} component - the Vue instance to get meta info from
* @return {Object} - returned meta info
*/
export default function getMetaInfo (component) {
// collect & aggregate all metaInfo $options
const info = getComponentOption({ component, option: 'metaInfo', deep: true })
// if any info options are a function, coerce them to the result of a call
for (let key in info) {
if (info.hasOwnProperty(key)) {
const value = info[key]
if (typeof value === 'function') {
info[key] = value()
}
}
}
// backup the title chunk
if (info.title) {
info.titleChunk = info.title
}
// replace title with populated template
if (info.titleTemplate && info.titleChunk) {
info.title = info.titleTemplate.replace(/%s/g, info.titleChunk)
}
return info
}