Skip to content

Commit 288871f

Browse files
committed
fix: use const arrays
1 parent 82ba8c0 commit 288871f

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

src/client/updateClientMetaInfo.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { metaInfoOptionKeys, metaInfoAttributeKeys } from '../shared/constants'
12
import { updateAttribute, updateTag, updateTitle } from './updaters'
23

34
const getTag = (tags, tag) => {
@@ -29,13 +30,7 @@ export default function updateClientMetaInfo(options = {}, newInfo) {
2930

3031
Object.keys(newInfo).forEach((type) => {
3132
// ignore these
32-
if ([
33-
'titleChunk',
34-
'titleTemplate',
35-
'changed',
36-
'__dangerouslyDisableSanitizers',
37-
'__dangerouslyDisableSanitizersByTagID'
38-
].includes(type)) {
33+
if (metaInfoOptionKeys.includes(type)) {
3934
return
4035
}
4136

@@ -45,7 +40,7 @@ export default function updateClientMetaInfo(options = {}, newInfo) {
4540
return
4641
}
4742

48-
if (['htmlAttrs', 'headAttrs', 'bodyAttrs'].includes(type)) {
43+
if (metaInfoAttributeKeys.includes(type)) {
4944
const tagName = type.substr(0, 4)
5045
updateAttribute(options, newInfo[type], getTag(tags, tagName))
5146
return

src/server/generateServerInjector.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { metaInfoAttributeKeys } from '../shared/constants'
12
import { titleGenerator, attributeGenerator, tagGenerator } from './generators'
23

34
/**
@@ -13,7 +14,7 @@ export default function generateServerInjector(options, type, data) {
1314
return titleGenerator(options, type, data)
1415
}
1516

16-
if (['htmlAttrs', 'headAttrs', 'bodyAttrs'].includes(type)) {
17+
if (metaInfoAttributeKeys.includes(type)) {
1718
return attributeGenerator(options, type, data)
1819
}
1920

src/server/generators/tag.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants'
2+
13
/**
24
* Generates meta, base, link, style, script, noscript tags for use on the server
35
*
@@ -21,7 +23,7 @@ export default function tagGenerator({ attribute, tagIDKeyName } = {}, type, tag
2123
// build a string containing all attributes of this tag
2224
const attrs = Object.keys(tag).reduce((attrsStr, attr) => {
2325
// these attributes are treated as children on the tag
24-
if (['innerHTML', 'cssText', 'once'].includes(attr)) {
26+
if (tagAttributeAsInnerContent.includes(attr) || attr === 'once') {
2527
return attrsStr
2628
}
2729

@@ -45,10 +47,10 @@ export default function tagGenerator({ attribute, tagIDKeyName } = {}, type, tag
4547
: `${attribute}="true"`
4648

4749
// these tags have no end tag
48-
const hasEndTag = !['base', 'meta', 'link'].includes(type)
50+
const hasEndTag = !tagsWithoutEndTag.includes(type)
4951

5052
// these tag types will have content inserted
51-
const hasContent = hasEndTag && ['noscript', 'script', 'style'].includes(type)
53+
const hasContent = hasEndTag && tagsWithInnerContent.includes(type)
5254

5355
// the final string for this specific tag
5456
return !hasContent

src/server/inject.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import getMetaInfo from '../shared/getMetaInfo'
2+
import { metaInfoOptionKeys } from '../shared/constants'
23
import generateServerInjector from './generateServerInjector'
34

45
export default function _inject(options = {}) {
@@ -16,7 +17,7 @@ export default function _inject(options = {}) {
1617

1718
// generate server injectors
1819
for (const key in metaInfo) {
19-
if (!['titleTemplate', 'titleChunk'].includes(key) && metaInfo.hasOwnProperty(key)) {
20+
if (!metaInfoOptionKeys.includes(key) && metaInfo.hasOwnProperty(key)) {
2021
metaInfo[key] = generateServerInjector(options, key, metaInfo[key])
2122
}
2223
}

src/shared/constants.js

+20
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,23 @@ export const VUE_META_TEMPLATE_KEY_NAME = 'template'
2525

2626
// This is the key name for the content-holding property
2727
export const VUE_META_CONTENT_KEY = 'content'
28+
29+
export const metaInfoOptionKeys = [
30+
'titleChunk',
31+
'titleTemplate',
32+
'changed',
33+
'__dangerouslyDisableSanitizers',
34+
'__dangerouslyDisableSanitizersByTagID'
35+
]
36+
37+
export const metaInfoAttributeKeys = [
38+
'htmlAttrs',
39+
'headAttrs',
40+
'bodyAttrs'
41+
]
42+
43+
export const tagsWithoutEndTag = ['base', 'meta', 'link']
44+
45+
export const tagsWithInnerContent = ['noscript', 'script', 'style']
46+
47+
export const tagAttributeAsInnerContent = ['innerHTML', 'cssText']

0 commit comments

Comments
 (0)