Skip to content

Instantly share code, notes, and snippets.

@somidad
Last active June 25, 2022 07:54
Show Gist options
  • Save somidad/b41dec1b348edc9e0fdfd60d43065d91 to your computer and use it in GitHub Desktop.
Save somidad/b41dec1b348edc9e0fdfd60d43065d91 to your computer and use it in GitHub Desktop.
Script to remove U+2029 from published Logseq graph for GitHub Pages
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