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):
    

  • 4 Votes
    4 Posts
    108 Views

    @Norrad Are you looking for anything in particular? I only ask because Sudonix uses a number of custom functions which I wrote, but all are available on GitHub and fully supported here.

  • 7 Votes
    8 Posts
    182 Views

    @crazycells hmm. That’s odd. I haven’t made any changes from recollection but I could be wrong. I’ll need to check.

    EDIT - very strange. I honestly don’t recall adding the below CSS block to alter the bottom bar, but you’re right…

    .bottombar-nav { padding: 0px !important; }

    I’ve removed this so it reflects stock Harmony.

  • Upgrade issues

    Solved Configure
    2
    2 Votes
    2 Posts
    136 Views

    Use this code

    git fetch # Grab the latest code from the NodeBB repository git checkout v3.x git reset --hard origin/v3.x

    And you will have the latest version without specifying it

    https://docs.nodebb.org/configuring/upgrade/

  • 1 Votes
    4 Posts
    165 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.

  • Smart Widgets

    Solved Configure
    9
    3 Votes
    9 Posts
    314 Views

    @Panda said in Smart Widgets:

    So why is that, or conversely why would the function to expose username ever be required, as it seems app.user is already an available global object?

    It is, yes, but not if you are using it outside of a widget. The function I wrote is also historical and comes from the 2.x train 🙂

  • 7 Votes
    7 Posts
    427 Views

    @phenomlab thank you very much 🙂

  • NodeBB metadata

    Solved Configure
    4
    2 Votes
    4 Posts
    368 Views

    @phenomlab said in NodeBB metadata:

    @jac Are you sure ?

    https://www.google.co.uk/search?q=site%3Astockportcounty.fans&sxsrf=AOaemvLwnaZL-PliU_2dBOg_Eo1pMVhBjg%3A1638982328139&source=hp&ei=uOKwYeatBcOsad3yp7AE&iflsig=ALs-wAMAAAAAYbDwyLBSDcG5XYoFCKwQFhgz94wTxOcV&ved=0ahUKEwjm6dX71NT0AhVDVhoKHV35CUYQ4dUDCAk&uact=5&oq=site%3Astockportcounty.fans&gs_lcp=Cgdnd3Mtd2l6EAM6BAgjECc6CwgAEIAEELEDEIMBOg4ILhCABBCxAxDHARCjAjoRCC4QgAQQsQMQgwEQxwEQowI6BQguEIAEOggIABCABBCxAzoFCAAQgAQ6CAguELEDEIMBOgsILhCABBDHARCvAToICC4QgAQQsQM6BQgAELEDOgsILhCABBDHARDRAzoLCAAQgAQQsQMQyQM6BQgAEJIDUABYySZg0CdoAHAAeACAAW2IAa0NkgEEMjMuMpgBAKABAQ&sclient=gws-wiz

    Fair enough 🤪🤪😁.

  • Nodebb Hashtag plugin

    Solved General
    15
    1 Votes
    15 Posts
    725 Views

    @jac Great ! I’ll close this off.