diff --git a/src/client/updateClientMetaInfo.js b/src/client/updateClientMetaInfo.js index 275d21f..45776b3 100644 --- a/src/client/updateClientMetaInfo.js +++ b/src/client/updateClientMetaInfo.js @@ -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 diff --git a/src/server/generateServerInjector.js b/src/server/generateServerInjector.js index d4d7bfe..225a401 100644 --- a/src/server/generateServerInjector.js +++ b/src/server/generateServerInjector.js @@ -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) } diff --git a/src/server/generators/tag.js b/src/server/generators/tag.js index b047f50..57861a7 100644 --- a/src/server/generators/tag.js +++ b/src/server/generators/tag.js @@ -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 diff --git a/src/server/inject.js b/src/server/inject.js index 133ed4a..1245cba 100644 --- a/src/server/inject.js +++ b/src/server/inject.js @@ -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]) } } diff --git a/src/shared/constants.js b/src/shared/constants.js index cff0289..90bab14 100644 --- a/src/shared/constants.js +++ b/src/shared/constants.js @@ -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']