Skip to content

Plugin to show images in teasers

General
  • Hi,

    Iā€™ve posted this on nodebb before but was hoping to get more response here if anyone is interested. šŸ™‚

    I was searching for a solution to show images, especially custom emojis, in teasers. Right now custom emojis or images are shown like ā€œxyz.pngā€ or ā€œ:emoji1:ā€:

    Screenshot 2023-06-08 at 12-39-45 Kategorien.png

    Regular emojis from emoji packs are displayed, I guess because the browser interprets ASCII.

    Iā€™ve then created a plugin using an intended solution found here. It should remove the img-tag from the configureStripTags Hook.

    Unfortunately there is no impact to the recent cards plugin or any other teasers. No regarding error or warning found in the nodebb log. This is part of the log when I run ./nodebb dev:

    verbose: [plugins] Loaded plugin: nodebb-plugin-teaser-image
    
    verbose: [plugins/fireHook] filter:teasers.configureStripTags
    

    Plugin is as basic as it can be:

    index.js:

    'use strict';
    
    var plugin = {};
    
    plugin.filterTeasersConfigureStripTags = async function (hookData) {
      // Check if the "img" tag is present in the tags array
      if (hookData.tags.includes('img')) {
        // Remove the "img" tag from the tags array
        hookData.tags = hookData.tags.filter(tag => tag !== 'img');
      }
    
      return hookData;
    };
    
    module.exports = plugin;
    

    package.json:

    {
      "name": "nodebb-plugin-teaser-image",
      "version": "1.0.0",
      "description": "NodeBB Plugin to show images in teasers",
      "main": "index.js",
      "dependencies": {},
      "nbbpm": {
        "compatibility": "^1.0.0 || ^2.0.0 || ^3.0.0"
      }
    }
    
    

    plugin.json:

    {
      "id": "nodebb-plugin-teaser-image",
      "name": "Show images in Teasers",
      "description": "A NodeBB plugin to show images in teasers",
      "version": "1.0.0",
      "hooks": [
        {
          "hook": "filter:teasers.configureStripTags",
          "method": "filterTeasersConfigureStripTags"
        }
      ]
    }
    
    

    Anything I have overlooked or any more information I could add? From my understanding, this should already work. šŸ¤” Help is appreciated. I donā€™t have a github link yet, If anyone wants to try you can just create a folder in node_modules and add the above files.

  • @dave1904 thereā€™s nothing wrong with the plugin youā€™ve written, but seeing as itā€™s a server side hook, have you changed the plugin load order so that yours is the last to load?

    It could well be that your plugin is being overridden by another.

  • @phenomlab said in Plugin to show images in teasers:

    have you changed the plugin load order so that yours is the last to load?

    Yes I did, the plugin is last in the plugin order list.

  • @dave1904 have you considered doing this client side? You could fairly easily manipulate the element in question using js.

    Admittedly, anyone using your site without script access wonā€™t be able to leverage this, but itā€™s an acceptable solution.

  • Thank you @phenomlab

    Client side development is something I would consider but I donā€™t like it when things donā€™t work and especially when I donā€™t know why they donā€™t work. Do you maybe have any idea where I could have a look for more troubleshooting? I see that the hook is fired but can I see anywhere what the hook is doing in detail?

  • @dave1904 Iā€™d start by adding a console.log function to hookData so you can see what is being returned

    return hookData;
    console.log(hookData):
    

Related Topics
  • 1 Votes
    4 Posts
    323 Views

    @Vijay-Kumavat-0 I think youā€™d be better off customising the plugin above to be honest. It seems like youā€™d be reinventing the wheel otherwise.

    Iā€™d modify

    /nodebb/node_modules/nodebb-rewards-essentials/lib/conditions.js
    /nodebb/node_modules/nodebb-rewards-essentials/lib/rewards.js

    These seem to be the two files that control what is in the dropdown lists.

  • 12 Votes
    47 Posts
    3k Views

    @dave1904 just coming back to this thread as @DownPW and I both experienced issues with other plugins today, and the fix was to use the plugin ordering in the ACP and move the Harmony theme to the very top so it comes before everything else in terms of other plugins.

    It might be worth at least trying this to see if it gives you a result rather than the previous bulldozer approach. Thinking about it, the previous fix I proposed is along the same lines and disabling plugins does in fact change the order when they are enabled again, so this is definitely worth a try.

    Let me know how you get on.

  • 1 Votes
    5 Posts
    653 Views

    @DownPW very useful tip. Thanks

  • NodeBB v3

    Announcements
    2
    3 Votes
    2 Posts
    229 Views

    @cagatay JS will work fine - no changes there, and there are no plans to drop support for jQuery. More of an issue is the CSS - for which there are quite a few breaking changes. Keep an eye on sudonix.dev (my development site) where you can see progress in relation to how I am tackling the compatibility issues.

  • NodeBB Footer

    Solved Customisation
    10
    1 Votes
    10 Posts
    1k Views

    @phenomlab said in NodeBB Footer:

    @jac and you. Hope all is well and you recover quickly

    Thanks pal šŸ˜šŸ¤šŸ»

  • Nodebb Hashtag plugin

    Solved General
    15
    1 Votes
    15 Posts
    949 Views

    @jac Great ! Iā€™ll close this off.

  • NodeBB vs Discourse

    Chitchat
    25
    6 Votes
    25 Posts
    2k Views

    @phenomlab said in NodeBB vs Discourse:

    Hetzner eh ? I use them also. In fact, Sudonix is hosted in Nuremberg šŸ‘

    yes iā€™m also at hetzner, i have been a customer there for years with a reseller account for domains. My VPS that I host there are also in Nuremberg šŸ™‚

  • Nodebb best plugins

    General
    18
    7 Votes
    18 Posts
    1k Views

    @phenomlab thanks šŸ™‚