Last active
June 25, 2022 07:54
-
-
Save somidad/b41dec1b348edc9e0fdfd60d43065d91 to your computer and use it in GitHub Desktop.
Script to remove U+2029 from published Logseq graph for GitHub Pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { readFileSync, writeFileSync } = require("fs"); | |
function indexOfUnicode(s, u) { | |
let i = -1; | |
for (i = 0; i < s.length; i++) { | |
if (s.charCodeAt(i) === u) { | |
break; | |
} | |
} | |
return i; | |
} | |
const filepath = "static/js/main.js"; | |
const content = readFileSync(filepath, "utf8"); | |
const i = indexOfUnicode(content, 0x2029); | |
if (i !== -1) { | |
const intermediate = | |
content.substring(0, i) + | |
"_PARAGRAPH_SEPARATOR_" + | |
content.substring(i + 1); | |
const replaced = intermediate.replace( | |
/"_PARAGRAPH_SEPARATOR_":"u2029",?/, | |
"" | |
); | |
writeFileSync(filepath, replaced, "utf8"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment