mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-14 08:42:25 +03:00
feat: make ssr app id configurable
This commit is contained in:
@@ -9,14 +9,14 @@ import { titleGenerator, attributeGenerator, tagGenerator } from './generators'
|
||||
* @return {Object} - the new injector
|
||||
*/
|
||||
|
||||
export default function generateServerInjector (appId, options, type, data) {
|
||||
export default function generateServerInjector (options, type, data) {
|
||||
if (type === 'title') {
|
||||
return titleGenerator(appId, options, type, data)
|
||||
return titleGenerator(options, type, data)
|
||||
}
|
||||
|
||||
if (metaInfoAttributeKeys.includes(type)) {
|
||||
return attributeGenerator(options, type, data)
|
||||
}
|
||||
|
||||
return tagGenerator(appId, options, type, data)
|
||||
return tagGenerator(options, type, data)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { booleanHtmlAttributes, tagsWithoutEndTag, tagsWithInnerContent, tagAttr
|
||||
* @param {(Array<Object>|Object)} tags - an array of tag objects or a single object in case of base
|
||||
* @return {Object} - the tag generator
|
||||
*/
|
||||
export default function tagGenerator (appId, { attribute, tagIDKeyName } = {}, type, tags) {
|
||||
export default function tagGenerator ({ ssrAppId, attribute, tagIDKeyName } = {}, type, tags) {
|
||||
return {
|
||||
text ({ body = false } = {}) {
|
||||
// build a string containing all tags of this type
|
||||
@@ -51,7 +51,7 @@ export default function tagGenerator (appId, { attribute, tagIDKeyName } = {}, t
|
||||
// generate tag exactly without any other redundant attribute
|
||||
const observeTag = tag.once
|
||||
? ''
|
||||
: `${attribute}="${appId}"`
|
||||
: `${attribute}="${ssrAppId}"`
|
||||
|
||||
// these tags have no end tag
|
||||
const hasEndTag = !tagsWithoutEndTag.includes(type)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @param {String} data - the title text
|
||||
* @return {Object} - the title generator
|
||||
*/
|
||||
export default function titleGenerator (appId, { attribute } = {}, type, data) {
|
||||
export default function titleGenerator ({ attribute } = {}, type, data) {
|
||||
return {
|
||||
text () {
|
||||
if (!data) {
|
||||
|
||||
@@ -18,7 +18,7 @@ export default function _inject (options = {}) {
|
||||
// generate server injectors
|
||||
for (const key in metaInfo) {
|
||||
if (!metaInfoOptionKeys.includes(key) && metaInfo.hasOwnProperty(key)) {
|
||||
metaInfo[key] = generateServerInjector('ssr', options, key, metaInfo[key])
|
||||
metaInfo[key] = generateServerInjector(options, key, metaInfo[key])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,13 +44,17 @@ export const metaTemplateKeyName = 'template'
|
||||
// This is the key name for the content-holding property
|
||||
export const contentKeyName = 'content'
|
||||
|
||||
// The id used for the ssr app
|
||||
export const ssrAppId = 'ssr'
|
||||
|
||||
export const defaultOptions = {
|
||||
keyName,
|
||||
attribute,
|
||||
ssrAttribute,
|
||||
tagIDKeyName,
|
||||
contentKeyName,
|
||||
metaTemplateKeyName
|
||||
metaTemplateKeyName,
|
||||
ssrAppId
|
||||
}
|
||||
|
||||
// List of metaInfo property keys which are configuration options (and dont generate html)
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ export default function createMixin (Vue, options) {
|
||||
// if this Vue-app was server rendered, set the appId to 'ssr'
|
||||
// only one SSR app per page is supported
|
||||
if (this.$root.$el && this.$root.$el.hasAttribute && this.$root.$el.hasAttribute('data-server-rendered')) {
|
||||
this.$root._vueMeta.appId = 'ssr'
|
||||
this.$root._vueMeta.appId = options.ssrAppId
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user