Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
HASTUtils.addTextNode(styleTag, asset.content)
HASTUtils.addChildNode(headNode, styleTag)
}
// script (external or inline)
if (asset.type === 'script') {
const scriptInBody = (asset.options && asset.options.target === 'body') || false
const scriptTag = HASTBuilers.createHTMLNode('script')
HASTUtils.addAttributeToNode(scriptTag, 'type', 'text/javascript')
if (assetPath) {
HASTUtils.addAttributeToNode(scriptTag, 'src', assetPath)
if (asset.options && asset.options.defer) {
HASTUtils.addBooleanAttributeToNode(scriptTag, 'defer')
}
if (asset.options && asset.options.async) {
HASTUtils.addBooleanAttributeToNode(scriptTag, 'async')
}
} else if (asset.content) {
HASTUtils.addTextNode(scriptTag, asset.content)
}
if (scriptInBody) {
HASTUtils.addChildNode(bodyNode, scriptTag)
} else {
HASTUtils.addChildNode(headNode, scriptTag)
}
}
// icon
if (asset.type === 'icon' && assetPath) {
const iconTag = HASTBuilers.createHTMLNode('link')
HASTUtils.addAttributeToNode(iconTag, 'rel', 'shortcut icon')
HASTUtils.addAttributeToNode(iconTag, 'href', assetPath)
// inline style
if (asset.type === 'style' && asset.content) {
const styleTag = HASTBuilers.createHTMLNode('style')
HASTUtils.addTextNode(styleTag, asset.content)
HASTUtils.addChildNode(headNode, styleTag)
}
// script (external or inline)
if (asset.type === 'script') {
const scriptInBody = (asset.options && asset.options.target === 'body') || false
const scriptTag = HASTBuilers.createHTMLNode('script')
HASTUtils.addAttributeToNode(scriptTag, 'type', 'text/javascript')
if (assetPath) {
HASTUtils.addAttributeToNode(scriptTag, 'src', assetPath)
if (asset.options && asset.options.defer) {
HASTUtils.addBooleanAttributeToNode(scriptTag, 'defer')
}
if (asset.options && asset.options.async) {
HASTUtils.addBooleanAttributeToNode(scriptTag, 'async')
}
} else if (asset.content) {
HASTUtils.addTextNode(scriptTag, asset.content)
}
if (scriptInBody) {
HASTUtils.addChildNode(bodyNode, scriptTag)
} else {
HASTUtils.addChildNode(headNode, scriptTag)
}
}
// icon
if (asset.type === 'icon' && assetPath) {
attributes.forEach((attribute: Attribute) => {
const { attributeKey, attributeValue } = attribute
if (attributeValue) {
HASTUtils.addAttributeToNode(createdNode, attributeKey, attributeValue)
} else {
HASTUtils.addBooleanAttributeToNode(createdNode, attributeKey)
}
})
}