⚡ (settings) Parse custom head code to remove invalid text nodes
This commit is contained in:
@ -287,7 +287,6 @@ export const parseNumberWithCommas = (num: number) =>
|
||||
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
|
||||
export const injectCustomHeadCode = (customHeadCode: string) => {
|
||||
customHeadCode = injectTryCatch(customHeadCode)
|
||||
const headCodes = customHeadCode.split('</noscript>')
|
||||
headCodes.forEach((headCode) => {
|
||||
const [codeToInject, noScriptContentToInject] = headCode.split('<noscript>')
|
||||
@ -307,29 +306,6 @@ export const injectCustomHeadCode = (customHeadCode: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
const injectTryCatch = (headCode: string) => {
|
||||
const scriptTagRegex = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi
|
||||
const scriptTags = headCode.match(scriptTagRegex)
|
||||
if (scriptTags) {
|
||||
scriptTags.forEach(function (tag) {
|
||||
const wrappedTag = tag.replace(
|
||||
/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi,
|
||||
function (_, openingTag, content, closingTag) {
|
||||
return `${openingTag}
|
||||
try {
|
||||
${content}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
${closingTag}`
|
||||
}
|
||||
)
|
||||
headCode = headCode.replace(tag, wrappedTag)
|
||||
})
|
||||
}
|
||||
return headCode
|
||||
}
|
||||
|
||||
export const getAtPath = <T>(obj: T, path: string): unknown => {
|
||||
if (isNotDefined(obj)) return undefined
|
||||
const pathParts = path.split('.')
|
||||
|
Reference in New Issue
Block a user