From 684a45811a19f8430c60f0ecbcaca6f4ef451022 Mon Sep 17 00:00:00 2001 From: Violet Date: Fri, 13 Sep 2024 10:42:32 -0500 Subject: [PATCH] revert c6b2f651711a4ab376a88f547a880f6190a71f97 revert Highlight rewrite --- pageUpdater.js | 209 +++++++++++++++++++------------------------------ 1 file changed, 80 insertions(+), 129 deletions(-) diff --git a/pageUpdater.js b/pageUpdater.js index dc01fa8..b4e35d3 100644 --- a/pageUpdater.js +++ b/pageUpdater.js @@ -111,166 +111,117 @@ function highlighter(json, full = true, linkParent = false) { if (element.tagName == "code") { valid = false } - + if (valid) { element.children = highlighter(element.children, full, linkParent || element.tagName == "a") } } } else if (element.type == "text") { + var index = 0 for (let i = 0; i < highlightedWords.length; i++) { var dict = highlightedWords[i] for (let x = 0; x < dict.words.length; x++) { + index += 1 var term = dict.words[x]; - var termWordCount = term.split(" ").length var termProps = dict - var reg = new RegExp(`(${term})`, "g") + var reg = term if (termProps.caseInsensitive) { reg = new RegExp(`(${term})`, "gi") } - - var style = termProps.style || "" - var classes = termProps.classes || "" - var link = termProps.link || "" - - if (termProps.color) { - style += `color: ${termProps.color};` - } - - if (termProps.italicized) { - style += "font-style: italic;" - } - - if (termProps.outline) { - var width = 2 - // style += `text-shadow: -1px -1px 0 ${termProps.outline}, 1px -1px 0 ${termProps.outline}, -1px 1px 0 ${termProps.outline}, 1px 1px 0 ${termProps.outline};` - style += `-webkit-text-stroke: 1px ${termProps.outline};` - // ^ Not in use because it looks bad :3 - } - - if (termProps.bold) { - classes += "bold" - } - - if (style.length > 2) { - style = `style="${style}"` - } - - if (classes.length > 2) { - classes = `class="${classes}"` - } - - - var splitContent = element.content.split(" ") - for (let y = 0; y < splitContent.length; y++) { - var word = splitContent[y] - - if (reg.test(word)) { - - if (link && !linkParent) { - splitContent[y] = `${splitContent[y]}` - } else { - splitContent[y] = `${splitContent[y]}` - } - } - } - - element.content = splitContent.join(" ") - - - // element.content = element.content.replaceAll(`{${term}}`, "TEMPORARY_REPLACE") - // element.content = element.content.replaceAll(reg, "{TERM" + index + "}") - // element.content = element.content.replaceAll("TEMPORARY_REPLACE", `${term}`) + element.content = element.content.replaceAll(`{${term}}`, "TEMPORARY_REPLACE") + element.content = element.content.replaceAll(reg, "{TERM" + index + "}") + element.content = element.content.replaceAll("TEMPORARY_REPLACE", `${term}`) } } - // if (full) { - // var index = 0 - // for (let i = 0; i < highlightedWords.length; i++) { - // var dict = highlightedWords[i] - // for (let x = 0; x < dict.words.length; x++) { - // index += 1 - // var termKey = "{TERM" + index + "}" - // var termProps = dict - // while (element.content.includes(termKey)) { - // var termIndex = element.content.indexOf(termKey) + if (full) { + var index = 0 + for (let i = 0; i < highlightedWords.length; i++) { + var dict = highlightedWords[i] + for (let x = 0; x < dict.words.length; x++) { + index += 1 + var termKey = "{TERM" + index + "}" + var termProps = dict + while (element.content.includes(termKey)) { + var termIndex = element.content.indexOf(termKey) - // var spanEnd = element.content.indexOf(" ", termIndex) + var spanEnd = element.content.indexOf(" ", termIndex) - // if (spanEnd == -1) { - // spanEnd = element.content.length - // } + if (spanEnd == -1) { + spanEnd = element.content.length + } - // var spanStart = element.content.substring(0, termIndex).lastIndexOf(" ") + 1 + var spanStart = element.content.substring(0, termIndex).lastIndexOf(" ") + 1 - // // if (highTable[index] == "ULTRAKILL") { - // // console.log(startContent, " ---- ", endContent) - // // } + // if (highTable[index] == "ULTRAKILL") { + // console.log(startContent, " ---- ", endContent) + // } - // var startContent = element.content.substring(spanStart - 1, termIndex) - // var endContent = element.content.substring(termIndex + termKey.length, spanEnd) + var startContent = element.content.substring(spanStart - 1, termIndex) + var endContent = element.content.substring(termIndex + termKey.length, spanEnd) - // // if (startContent.includes("(") && !endContent.includes(")")) { - // // spanEnd = element.content.indexOf(")", spanStart) + 1 - // // endContent = element.content.substring(termIndex + termKey.length, spanEnd) - // // } - // // else if (endContent.includes(")") && !startContent.includes("(")) { - // // spanStart = element.content.substring(0, spanStart).lastIndexOf("(") - // // startContent = element.content.substring(spanStart - 1, termIndex) - // // } + // if (startContent.includes("(") && !endContent.includes(")")) { + // spanEnd = element.content.indexOf(")", spanStart) + 1 + // endContent = element.content.substring(termIndex + termKey.length, spanEnd) + // } + // else if (endContent.includes(")") && !startContent.includes("(")) { + // spanStart = element.content.substring(0, spanStart).lastIndexOf("(") + // startContent = element.content.substring(spanStart - 1, termIndex) + // } - // var style = termProps.style || "" - // var classes = termProps.classes || "" - // var link = termProps.link || "" + var style = termProps.style || "" + var classes = termProps.classes || "" + var link = termProps.link || "" - // if (termProps.color) { - // style += `color: ${termProps.color};` - // } + if (termProps.color) { + style += `color: ${termProps.color};` + } - // if (termProps.italicized) { - // style += "font-style: italic;" - // } + if (termProps.italicized) { + style += "font-style: italic;" + } - // if (termProps.outline) { - // var width = 2 - // // style += `text-shadow: -1px -1px 0 ${termProps.outline}, 1px -1px 0 ${termProps.outline}, -1px 1px 0 ${termProps.outline}, 1px 1px 0 ${termProps.outline};` - // style += `-webkit-text-stroke: 1px ${termProps.outline};` - // // ^ Not in use because it looks bad :30 - // } + if (termProps.outline) { + var width = 2 + // style += `text-shadow: -1px -1px 0 ${termProps.outline}, 1px -1px 0 ${termProps.outline}, -1px 1px 0 ${termProps.outline}, 1px 1px 0 ${termProps.outline};` + style += `-webkit-text-stroke: 1px ${termProps.outline};` + // ^ Not in use because it looks bad :30 + } - // if (termProps.bold) { - // classes += "bold" - // } + if (termProps.bold) { + classes += "bold" + } - // if (style.length > 2) { - // style = `style="${style}"` - // } + if (style.length > 2) { + style = `style="${style}"` + } - // if (classes.length > 2) { - // classes = `class="${classes}"` - // } + if (classes.length > 2) { + classes = `class="${classes}"` + } - // var stuff = (startContent + dict.words[x] + endContent).trim() + var stuff = (startContent + dict.words[x] + endContent).trim() - // if (!stuff.includes("span")) { - // var replacement = `${stuff}` + if (!stuff.includes("span")) { + var replacement = `${stuff}` - // if (link && !linkParent) { - // replacement = `${replacement}` - // // console.log(replacement) - // } - // element.content = element.content.substring(0, spanStart) + replacement + element.content.substring(spanEnd) - // } else { + if (link && !linkParent) { + replacement = `${replacement}` + // console.log(replacement) + } + element.content = element.content.substring(0, spanStart) + replacement + element.content.substring(spanEnd) + } else { - // element.content = element.content.replace(termKey, dict.words[x]) - // } - // } - // } - // } + element.content = element.content.replace(termKey, dict.words[x]) + } + } + } + } - // // element.content = element.content.replaceAll(termKey, replacement) - // } + // element.content = element.content.replaceAll(termKey, replacement) + } } } @@ -280,7 +231,7 @@ function highlighter(json, full = true, linkParent = false) { function converter(html, dynamic = true) { var startTime = Date.now() var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config/config.json'))) - + var staticReplacers = { "ALL_HIGHLIGHTS": () => { var addedHTML = "" @@ -360,7 +311,7 @@ function converter(html, dynamic = true) { var siteName = sitesTable[x] var siteData = sites[siteName] html += `${siteName}: ${siteData.name}` - + } html += "" } @@ -372,8 +323,8 @@ function converter(html, dynamic = true) { for (var i in api.blogPosts) { var post = api.blogPosts[i] if (!post.hidden) { - addedHTML += - `
+ addedHTML += + `

${post.title}

${post.desc}

@@ -487,7 +438,7 @@ module.exports = { } res.send(data) - } + } else { next() }