Parse emoji in title and tags
-
Here is a sample that works server side, I added the
filter:topics.get
hook in plugin.json.{ "hook": "filter:topics.get", "method": "filterTopicsGet" }
Then in library.js this is how the titles are parsed, since emoji uses the
filter:parse.raw
hook it turns the:smile:
into an emoji.library.filterTopicsGet = async (hookData) => { const plugins = require.main.require('./src/plugins'); await Promise.all(hookData.topics.map(async (t) => { t.title = await plugins.hooks.fire('filter:parse.raw', t.title); })); return hookData; };
-
@baris I tried this decision for the test, step by step:
1. go to pc
2. add this in parse.ts
export async function topic(data: { topicData: { content: string } }): Promise<any> { // eslint-disable-next-line no-param-reassign data.topicData.title = await parse(data.topicData.title); return data; }
3. add this in plugin.json
{ "hook": "filter:topics.get", "method": "filterTopicsGet" }
4. add this in parse.ts (because emoji plugin don't have
library.js and in emoji.js from android emoji pluginlibrary.filterTopicsGet = async (hookData) => { const plugins = require.main.require('./src/plugins'); await Promise.all(hookData.topics.map(async (t) => { t.title = await plugins.hooks.fire('filter:parse.raw', t.title); })); return hookData; };
rebuild/restart, but emoji is still not displayed in the titles...
I probably still be too stupid for such tricks #script-kiddie. -
So I went ahead and implemented this myself here:
Parse emoji in titles by pitaj · Pull Request #61 · NodeBB/nodebb-plugin-emoji
unfortunately has some issues
GitHub (github.com)
Unfortunately NodeBB is not built for this kind of formatting in titles:
-
@PitaJ said in Parse emoji in title and tags:
Parse emoji in titles by pitaj · Pull Request #61 · NodeBB/nodebb-plugin-emoji
unfortunately has some issues
GitHub (github.com)
I added all this changes in emoji plugin (harmony theme), nothing...
I also don't see new settings on the emoji plugin page/admin/plugins/emoji
, very strange...Trying manually enable this setting via
parseTitles: true
, not helps. -
@brazzerstop alright, I've just published
[email protected]
which has a setting that enables topic title parsing. It only support NodeBB v3, but should work well with the fixes baris has made in the themes. -
-
-
UPD
Tags not parse
I'm a copy this changes in my test fork, with replace
parseTitles
toparseTags
and add new codeparse.ts
export async function topic(data: { topic: { tags: string } }): Promise<any> { if (options.tags) { // eslint-disable-next-line no-param-reassign data.topic.tags= await parse(data.topic.tags); } return data; } export async function topics(data: { topics: [{ tags: string }] }): Promise<any> { if (options.tags) { await Promise.all(data.topics.map(async (t) => { // eslint-disable-next-line no-param-reassign t.tags= await parse(t.tags); })); } return data; }
with replace
parseTitles
toparseTags
, but get error when start install:root@server:/var/www/nodebb# npm install ferumdev/nodebb-plugin-emoji-dev npm WARN deprecated [email protected]: Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10. npm ERR! code 1 npm ERR! git dep preparation failed npm ERR! command /usr/bin/node /usr/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/root/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run npm ERR! > [email protected] prepare npm ERR! > bash prepare.sh npm ERR! npm ERR! npm ERR! > [email protected] pretest npm ERR! > npm run lint && npm run build npm ERR! npm ERR! npm ERR! > [email protected] lint npm ERR! > eslint . && svelte-check npm ERR! npm ERR! npm ERR! /root/.npm/_cacache/tmp/git-clonee5Qt7L/acp/src/Emoji.svelte npm ERR! 137:9 warning Unexpected console statement no-console npm ERR! npm ERR! /root/.npm/_cacache/tmp/git-clonee5Qt7L/lib/controllers.ts npm ERR! 38:1 error Unexpected tab character no-tabs npm ERR! 38:1 error Mixed spaces and tabs no-mixed-spaces-and-tabs npm ERR! npm ERR! /root/.npm/_cacache/tmp/git-clonee5Qt7L/lib/index.ts npm ERR! 12:36 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any npm ERR! 23:1 error Unexpected tab character no-tabs npm ERR! 23:1 error Expected indentation of 4 spaces but found 1 tab @typescript-eslint/indent npm ERR! 23:1 error Expected indentation of 4 spaces but found 1 tab indent npm ERR! 73:41 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any npm ERR! 73:55 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any npm ERR! npm ERR! /root/.npm/_cacache/tmp/git-clonee5Qt7L/lib/parse.ts npm ERR! 206:78 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any npm ERR! 212:74 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any npm ERR! 220:78 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any npm ERR! 230:1 error More than 1 blank line not allowed no-multiple-empty-lines npm ERR! 232:75 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any npm ERR! npm ERR! /root/.npm/_cacache/tmp/git-clonee5Qt7L/lib/settings.ts npm ERR! 40:1 error Unexpected tab character no-tabs npm ERR! 40:1 error Expected indentation of 4 spaces but found 1 tab @typescript-eslint/indent npm ERR! 40:1 error Expected indentation of 4 spaces but found 1 tab indent npm ERR! 49:1 error Unexpected tab character no-tabs npm ERR! 49:1 error Expected indentation of 4 spaces but found 1 tab @typescript-eslint/indent npm ERR! 49:1 error Expected indentation of 4 spaces but found 1 tab indent npm ERR! npm ERR! /root/.npm/_cacache/tmp/git-clonee5Qt7L/lib/types.d.ts npm ERR! 123:27 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any npm ERR! npm ERR! /root/.npm/_cacache/tmp/git-clonee5Qt7L/public/lib/emoji-dialog.ts npm ERR! 186:7 warning Unexpected console statement no-console npm ERR! npm ERR! /root/.npm/_cacache/tmp/git-clonee5Qt7L/public/lib/emoji.ts npm ERR! 85:11 warning Assignment to property of function parameter 'obj' no-param-reassign npm ERR! 92:11 warning Assignment to property of function parameter 'obj' no-param-reassign npm ERR! 99:11 warning Assignment to property of function parameter 'obj' no-param-reassign npm ERR! 124:5 warning Unexpected console statement no-console npm ERR! npm ERR! ✖ 26 problems (12 errors, 14 warnings) npm ERR! 7 errors and 0 warnings potentially fixable with the `--fix` option. npm ERR! npm WARN using --force Recommended protections disabled. npm ERR! npm WARN deprecated @types/[email protected]: This is a stub types definition. sass provides its own type definitions, so you do not need this installed. npm ERR! npm WARN deprecated [email protected]: Please use @jridgewell/sourcemap-codec instead npm ERR! npm WARN deprecated [email protected]: Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10. npm ERR! rm: cannot remove 'build': No such file or directory npm ERR! npm WARN using --force Recommended protections disabled. npm ERR! npm WARN using --force Recommended protections disabled. npm ERR! npm ERR! code 1 npm ERR! npm ERR! path /root/.npm/_cacache/tmp/git-clonee5Qt7L npm ERR! npm ERR! command failed npm ERR! npm ERR! command sh -c -- bash prepare.sh npm ERR! npm ERR! npm ERR! A complete log of this run can be found in: npm ERR! npm ERR! /root/.npm/_logs/2023-04-26T22_38_58_090Z-debug-0.log npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2023-04-26T22_38_50_584Z-debug-0.log