Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
if (asset.options && asset.options.iconType) {
HASTUtils.addAttributeToNode(iconTag, 'type', asset.options.iconType)
}
if (asset.options && asset.options.iconSizes) {
HASTUtils.addAttributeToNode(iconTag, 'sizes', asset.options.iconSizes)
}
HASTUtils.addChildNode(headNode, iconTag)
}
})
}
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)
if (asset.options && asset.options.iconType) {
HASTUtils.addAttributeToNode(iconTag, 'type', asset.options.iconType)
}
if (asset.options && asset.options.iconSizes) {
HASTUtils.addAttributeToNode(iconTag, 'sizes', asset.options.iconSizes)
}
HASTUtils.addChildNode(headNode, iconTag)
}
})
assets.forEach((asset) => {
const assetPath = UIDLUtils.prefixAssetsPath(assetsPrefix, asset.path)
// link canonical for SEO
if (asset.type === 'canonical' && assetPath) {
const linkTag = HASTBuilers.createHTMLNode('link')
HASTUtils.addAttributeToNode(linkTag, 'rel', 'canonical')
HASTUtils.addAttributeToNode(linkTag, 'href', assetPath)
HASTUtils.addChildNode(headNode, linkTag)
}
// link stylesheet (external css, font)
if ((asset.type === 'style' || asset.type === 'font') && assetPath) {
const linkTag = HASTBuilers.createHTMLNode('link')
HASTUtils.addAttributeToNode(linkTag, 'rel', 'stylesheet')
HASTUtils.addAttributeToNode(linkTag, 'href', assetPath)
HASTUtils.addChildNode(headNode, linkTag)
}
// 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 (attributeValue) {
HASTUtils.addAttributeToNode(createdNode, attributeKey, attributeValue)
} else {
HASTUtils.addBooleanAttributeToNode(createdNode, attributeKey)
}
})
}
HASTUtils.addChildNode(targetNode, createdNode)
})
}
if (manifest) {
const linkTag = HASTBuilers.createHTMLNode('link')
HASTUtils.addAttributeToNode(linkTag, 'rel', 'manifest')
HASTUtils.addAttributeToNode(linkTag, 'href', `${options.assetsPrefix}/manifest.json`)
HASTUtils.addChildNode(headNode, linkTag)
}
meta.forEach((metaItem) => {
const metaTag = HASTBuilers.createHTMLNode('meta')
Object.keys(metaItem).forEach((key) => {
const prefixedURL = UIDLUtils.prefixAssetsPath(assetsPrefix, metaItem[key])
HASTUtils.addAttributeToNode(metaTag, key, prefixedURL)
})
HASTUtils.addChildNode(headNode, metaTag)
})
assets.forEach((asset) => {
const assetPath = UIDLUtils.prefixAssetsPath(assetsPrefix, asset.path)
// link canonical for SEO
if (templateStyle === 'html') {
HASTUtils.addClassToNode(root, className)
} else {
ASTUtils.addClassStringOnJSXTag(root, className, classAttributeName)
}
}
if (Object.keys(dynamicStyles).length > 0) {
const rootStyles = UIDLUtils.cleanupNestedStyles(dynamicStyles)
// If dynamic styles are on nested-styles they are unfortunately lost, since inline style does not support that
if (Object.keys(rootStyles).length > 0) {
if (templateStyle === 'html') {
// simple string expression
const inlineStyles = createDynamicInlineStyle(rootStyles)
HASTUtils.addAttributeToNode(root, inlineStyleAttributeKey, `{${inlineStyles}}`)
} else {
// jsx object expression
const inlineStyles = UIDLUtils.transformDynamicStyles(rootStyles, (styleValue) =>
StyleBuilders.createDynamicStyleExpression(styleValue, propsPrefix)
)
ASTUtils.addAttributeToJSXTag(root, inlineStyleAttributeKey, inlineStyles)
}
}
}
})
HASTUtils.addAttributeToNode(linkTag, 'href', assetPath)
HASTUtils.addChildNode(headNode, linkTag)
}
// 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)
}
HASTUtils.addChildNode(htmlNode, headNode)
HASTUtils.addChildNode(htmlNode, bodyNode)
// Vue and React use a standard <div id="app"> in the body tag.
// Nuxt has an internal templating so requires an override
if (appRootOverride) {
HASTUtils.addTextNode(bodyNode, appRootOverride)
} else {
const appRootNode = HASTBuilers.createHTMLNode('div')
HASTUtils.addAttributeToNode(appRootNode, 'id', 'app')
HASTUtils.addChildNode(bodyNode, appRootNode)
}
if (settings.language) {
HASTUtils.addAttributeToNode(htmlNode, 'lang', settings.language)
}
if (settings.title) {
const titleTag = HASTBuilers.createHTMLNode('title')
HASTUtils.addTextNode(titleTag, settings.title)
HASTUtils.addChildNode(headNode, titleTag)
}
/* For frameworks that need to inject and point out the generated build files
or adding some script tags in head or body */
if (customTags.length > 0) {
customTags.forEach((tag: CustomTag) => {
const { targetTag, tagName, attributes, content } = tag
const targetNode = targetTag === 'head' ? headNode : bodyNode
const createdNode = HASTBuilers.createHTMLNode(tagName)
</div>
} 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)
if (asset.options && asset.options.iconType) {
HASTUtils.addAttributeToNode(iconTag, 'type', asset.options.iconType)
}
if (asset.options && asset.options.iconSizes) {
HASTUtils.addAttributeToNode(iconTag, 'sizes', asset.options.iconSizes)
}
HASTUtils.addChildNode(headNode, iconTag)
}
})
attributes.forEach((attribute: Attribute) => {
const { attributeKey, attributeValue } = attribute
if (attributeValue) {
HASTUtils.addAttributeToNode(createdNode, attributeKey, attributeValue)
} else {
HASTUtils.addBooleanAttributeToNode(createdNode, attributeKey)
}
})
}
const { attributeKey, attributeValue } = attribute
if (attributeValue) {
HASTUtils.addAttributeToNode(createdNode, attributeKey, attributeValue)
} else {
HASTUtils.addBooleanAttributeToNode(createdNode, attributeKey)
}
})
}
HASTUtils.addChildNode(targetNode, createdNode)
})
}
if (manifest) {
const linkTag = HASTBuilers.createHTMLNode('link')
HASTUtils.addAttributeToNode(linkTag, 'rel', 'manifest')
HASTUtils.addAttributeToNode(linkTag, 'href', `${options.assetsPrefix}/manifest.json`)
HASTUtils.addChildNode(headNode, linkTag)
}
meta.forEach((metaItem) => {
const metaTag = HASTBuilers.createHTMLNode('meta')
Object.keys(metaItem).forEach((key) => {
const prefixedURL = UIDLUtils.prefixAssetsPath(assetsPrefix, metaItem[key])
HASTUtils.addAttributeToNode(metaTag, key, prefixedURL)
})
HASTUtils.addChildNode(headNode, metaTag)
})
assets.forEach((asset) => {
const assetPath = UIDLUtils.prefixAssetsPath(assetsPrefix, asset.path)