Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const generateStyledJSXTag = (content: string): types.JSXElement => {
const templateLiteral = ASTUtils.stringAsTemplateLiteral(content)
const styleContent = ASTBuilders.createJSXExpresionContainer(templateLiteral)
const styleTag = ASTBuilders.createJSXTag('style', [styleContent])
ASTUtils.addChildJSXText(styleTag, '\n') // for better formatting
ASTUtils.addAttributeToJSXTag(styleTag, 'jsx')
return styleTag
}
const componentChunk = chunks.find((chunk) => chunk.name === componentChunkName)
if (!componentChunk) {
throw new Error(
`JSX component chunk with name ${componentChunkName} was required and not found.`
)
}
if (!uidl.seo) {
return structure
}
const headASTTags = []
if (uidl.seo.title) {
const titleAST = ASTBuilders.createJSXTag('title')
ASTUtils.addChildJSXText(titleAST, uidl.seo.title)
headASTTags.push(titleAST)
}
if (uidl.seo.metaTags) {
uidl.seo.metaTags.forEach((tag) => {
const metaAST = ASTBuilders.createSelfClosingJSXTag('meta')
Object.keys(tag).forEach((key) => {
ASTUtils.addAttributeToJSXTag(metaAST, key, tag[key])
})
headASTTags.push(metaAST)
})
}
if (uidl.seo.assets) {
uidl.seo.assets.forEach((asset) => {
// TODO: Handle other asset types when needed
ASTUtils.addAttributeToJSXTag(httpMetaTag, 'httpEquiv', 'x-ua-compatible')
ASTUtils.addAttributeToJSXTag(httpMetaTag, 'content', 'ie=edge')
ASTUtils.addChildJSXTag(headNode, httpMetaTag)
const viewPortMeta = ASTBuilders.createSelfClosingJSXTag('meta')
ASTUtils.addAttributeToJSXTag(viewPortMeta, 'name', 'viewport')
ASTUtils.addAttributeToJSXTag(
viewPortMeta,
'content',
'width=device-width, initial-scale=1, shrink-to-fit=no'
)
ASTUtils.addChildJSXTag(headNode, viewPortMeta)
addJSXExpressionContainer(bodyNode, 'props', 'preBodyComponents')
ASTUtils.addChildJSXText(noScriptNode, 'This app works best with JavaScript enabled.')
ASTUtils.addAttributeToJSXTag(noScriptNode, 'key', 'noscript')
ASTUtils.addAttributeToJSXTag(noScriptNode, 'id', 'gatsby-noscript')
ASTUtils.addChildJSXTag(bodyNode, noScriptNode)
addSpreadAttributes(htmlNode, 'props', 'htmlAttributes')
addSpreadAttributes(bodyNode, 'props', 'bodyAttributes')
addJSXExpressionContainer(headNode, 'props', 'headComponents')
if (settings.language) {
ASTUtils.addAttributeToJSXTag(htmlNode, 'lang', settings.language)
}
ASTBuilders.appendAssetsAST(assets, options, headNode, bodyNode)
meta.forEach((metaItem) => {
const metaTag = ASTBuilders.createJSXTag('meta')