mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-05-17 05:19:37 +03:00
fix: use const arrays
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { metaInfoOptionKeys, metaInfoAttributeKeys } from '../shared/constants'
|
||||
import { updateAttribute, updateTag, updateTitle } from './updaters'
|
||||
|
||||
const getTag = (tags, tag) => {
|
||||
@@ -29,13 +30,7 @@ export default function updateClientMetaInfo(options = {}, newInfo) {
|
||||
|
||||
Object.keys(newInfo).forEach((type) => {
|
||||
// ignore these
|
||||
if ([
|
||||
'titleChunk',
|
||||
'titleTemplate',
|
||||
'changed',
|
||||
'__dangerouslyDisableSanitizers',
|
||||
'__dangerouslyDisableSanitizersByTagID'
|
||||
].includes(type)) {
|
||||
if (metaInfoOptionKeys.includes(type)) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -45,7 +40,7 @@ export default function updateClientMetaInfo(options = {}, newInfo) {
|
||||
return
|
||||
}
|
||||
|
||||
if (['htmlAttrs', 'headAttrs', 'bodyAttrs'].includes(type)) {
|
||||
if (metaInfoAttributeKeys.includes(type)) {
|
||||
const tagName = type.substr(0, 4)
|
||||
updateAttribute(options, newInfo[type], getTag(tags, tagName))
|
||||
return
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { metaInfoAttributeKeys } from '../shared/constants'
|
||||
import { titleGenerator, attributeGenerator, tagGenerator } from './generators'
|
||||
|
||||
/**
|
||||
@@ -13,7 +14,7 @@ export default function generateServerInjector(options, type, data) {
|
||||
return titleGenerator(options, type, data)
|
||||
}
|
||||
|
||||
if (['htmlAttrs', 'headAttrs', 'bodyAttrs'].includes(type)) {
|
||||
if (metaInfoAttributeKeys.includes(type)) {
|
||||
return attributeGenerator(options, type, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants'
|
||||
|
||||
/**
|
||||
* Generates meta, base, link, style, script, noscript tags for use on the server
|
||||
*
|
||||
@@ -21,7 +23,7 @@ export default function tagGenerator({ attribute, tagIDKeyName } = {}, type, tag
|
||||
// build a string containing all attributes of this tag
|
||||
const attrs = Object.keys(tag).reduce((attrsStr, attr) => {
|
||||
// these attributes are treated as children on the tag
|
||||
if (['innerHTML', 'cssText', 'once'].includes(attr)) {
|
||||
if (tagAttributeAsInnerContent.includes(attr) || attr === 'once') {
|
||||
return attrsStr
|
||||
}
|
||||
|
||||
@@ -45,10 +47,10 @@ export default function tagGenerator({ attribute, tagIDKeyName } = {}, type, tag
|
||||
: `${attribute}="true"`
|
||||
|
||||
// these tags have no end tag
|
||||
const hasEndTag = !['base', 'meta', 'link'].includes(type)
|
||||
const hasEndTag = !tagsWithoutEndTag.includes(type)
|
||||
|
||||
// these tag types will have content inserted
|
||||
const hasContent = hasEndTag && ['noscript', 'script', 'style'].includes(type)
|
||||
const hasContent = hasEndTag && tagsWithInnerContent.includes(type)
|
||||
|
||||
// the final string for this specific tag
|
||||
return !hasContent
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import getMetaInfo from '../shared/getMetaInfo'
|
||||
import { metaInfoOptionKeys } from '../shared/constants'
|
||||
import generateServerInjector from './generateServerInjector'
|
||||
|
||||
export default function _inject(options = {}) {
|
||||
@@ -16,7 +17,7 @@ export default function _inject(options = {}) {
|
||||
|
||||
// generate server injectors
|
||||
for (const key in metaInfo) {
|
||||
if (!['titleTemplate', 'titleChunk'].includes(key) && metaInfo.hasOwnProperty(key)) {
|
||||
if (!metaInfoOptionKeys.includes(key) && metaInfo.hasOwnProperty(key)) {
|
||||
metaInfo[key] = generateServerInjector(options, key, metaInfo[key])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,3 +25,23 @@ export const VUE_META_TEMPLATE_KEY_NAME = 'template'
|
||||
|
||||
// This is the key name for the content-holding property
|
||||
export const VUE_META_CONTENT_KEY = 'content'
|
||||
|
||||
export const metaInfoOptionKeys = [
|
||||
'titleChunk',
|
||||
'titleTemplate',
|
||||
'changed',
|
||||
'__dangerouslyDisableSanitizers',
|
||||
'__dangerouslyDisableSanitizersByTagID'
|
||||
]
|
||||
|
||||
export const metaInfoAttributeKeys = [
|
||||
'htmlAttrs',
|
||||
'headAttrs',
|
||||
'bodyAttrs'
|
||||
]
|
||||
|
||||
export const tagsWithoutEndTag = ['base', 'meta', 'link']
|
||||
|
||||
export const tagsWithInnerContent = ['noscript', 'script', 'style']
|
||||
|
||||
export const tagAttributeAsInnerContent = ['innerHTML', 'cssText']
|
||||
|
||||
Reference in New Issue
Block a user