Created
February 17, 2021 17:47
-
-
Save ahwayakchih/c8c7f89849fe16936384596286672dd8 to your computer and use it in GitHub Desktop.
Custom function for converting posts content from IPBoard to NodeBB using nodebb-plugin-import module
This file contains 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
// Custom convert function for nodebb import plugin | |
content = content && encoding.convert(content, 'utf8', 'ISO-8859-2'); | |
content = content && content.toString('utf8'); | |
// This depends on changes implemented in https://github.com/ahwayakchih/nodebb-plugin-import/tree/feat-pass-type-and-id-to-custom-js | |
// It also assumes that HTML-to-Markdown conversion will be enabled too | |
// This is quite slow. Regexes probably could be optimized a bit, but it's a one-time-use-and-forget operation, so not much point i guess | |
if (type == 'post') { | |
content = content && content | |
.replace(/<!--quoteo\(post=(\d+)[^)]+name=([^):]+)[\w\W]+?<a\s+href="([^"]+)"[\w\W]+?<!--quotec-->([\w\W]+?)<!--QuoteEnd-->[\w\W]+?<!--QuoteEEnd-->/g, (m, pid, name, link, text) => { | |
// Later version of quotes includes marked user name, post id, etc... | |
return `[:arrow_upper_left:](${link.replace(/^index\.php/, '/index.php')})@${name.replace(/\s+/g, '-')}:<br />> ${text.replace(/<br\s*\/?>/g, `<br />> `)}<br />`; | |
}) | |
.replace(/<!--quoteo[\w\W]+?<!--quotec--><i>[^\s]+\s+([^<>]+)<\/i>([\w\W]+?)<!--QuoteEnd-->[\w\W]+?<!--QuoteEEnd-->/g, (m, name, text) => { | |
// Earlier version of quotes did not mark user name, nor add link or post id | |
return `@${name.replace(/\s+/g, '-')}:<br />> ${text.replace(/<br\s*\/?>/g, `<br />> `)}<br />`; | |
}) | |
.replace(/<img[^<>]+(?:<#EMO_DIR#>[^<>]+)?emoid="([^"]+)"[^<>]+>/g, (m, smily) => { | |
return smily; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment