mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-15 11:22:25 +03:00
refactor: extract applyTemplate method and make it more generic
This commit is contained in:
committed by
Alexander Lichter
parent
15eb9ccfd1
commit
fa90902fc7
@@ -0,0 +1,24 @@
|
||||
import { isUndefined, isFunction } from './typeof'
|
||||
|
||||
export default function applyTemplate({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) {
|
||||
if (isUndefined(template)) {
|
||||
template = headObject[metaTemplateKeyName]
|
||||
delete headObject[metaTemplateKeyName]
|
||||
}
|
||||
|
||||
// return early if no template defined
|
||||
if (!template) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isUndefined(chunk)) {
|
||||
chunk = headObject[contentKeyName]
|
||||
}
|
||||
|
||||
if (isFunction(template)) {
|
||||
headObject[contentKeyName] = template.call(component, chunk)
|
||||
} else {
|
||||
headObject[contentKeyName] = template.replace(/%s/g, chunk)
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user