Skip to content

Commit

Permalink
fix: use const arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Feb 10, 2019
1 parent 82ba8c0 commit 288871f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
11 changes: 3 additions & 8 deletions src/client/updateClientMetaInfo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { metaInfoOptionKeys, metaInfoAttributeKeys } from '../shared/constants'
import { updateAttribute, updateTag, updateTitle } from './updaters'

const getTag = (tags, tag) => {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/server/generateServerInjector.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { metaInfoAttributeKeys } from '../shared/constants'
import { titleGenerator, attributeGenerator, tagGenerator } from './generators'

/**
Expand All @@ -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)
}

Expand Down
8 changes: 5 additions & 3 deletions src/server/generators/tag.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants'

/**
* Generates meta, base, link, style, script, noscript tags for use on the server
*
Expand All @@ -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
}

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/server/inject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import getMetaInfo from '../shared/getMetaInfo'
import { metaInfoOptionKeys } from '../shared/constants'
import generateServerInjector from './generateServerInjector'

export default function _inject(options = {}) {
Expand All @@ -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])
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']

0 comments on commit 288871f

Please sign in to comment.