I created a plugin that extends the onebox functionality for a website that lots of users of my forum use.
This onebox also displays an image from the aforementioned website. Is there a way to store the image locally so that the onebox doesn’t break when the image changes on the source website?
I’ve seen that such a feature is available on the forum, but I can’t find the way to access it on the plugin I created.
Thank you very much in advance!
PS: Here is the github repository of the plugin I created. Any feedback on my code would be greatly appreciated.
(It’s the first time I code in Ruby coming from a NodeJS backend background).
Onebox & Discourse will do this natively without any additional plugins.
You just have to make sure that the target website generates the appropriate og meta tags. If anything you need to be modifying the target website, not Discourse, if you want this to work.
The BBC website generates those meta tags for each page. Discourse and onebox will pull in site_name, image, description and title and generate the onebox.
Just make sure your target website is following that standard and you shouldn’t need to do anything else?
It makes sense to do that because then your website is covered for all previews on other platforms too, e.g. Facebook.
I’m assuming you have control of or influence over this website, however, which might be a big assumption!
If this is not possible you are going to have to create some bespoke engine in Onebox that can recognise the uniqueness of that website and crawl it for the appropriate meta data. The Nokogiri library is the appropriate tool for that job.
Unfortunately not And besides that, I want to customize the onebox view a bit. This wouldn’t be possible if I were using the default engine.
I have already developed the onebox extension. It does all the fetching work and it works nice!
The question is: How can I be sure that the image fetched will be stored locally? I assume I need to write some extra code on the plugin.
Some avenues to explore:
The Cooked Post Processor enqueues a job to do this, see:
The jobs code is here: https://github.com/discourse/discourse/blob/e98c7b15d6ce864f1b5e83b6881700eaa808bdd1/app/jobs/regular/pull_hotlinked_images.rb
If you’ve managed to return the hotlinked images to the post, the images meet the criteria and settings ensure external images are uploaded, this should work.
Criteria here: https://github.com/discourse/discourse/blob/e98c7b15d6ce864f1b5e83b6881700eaa808bdd1/lib/cooked_post_processor.rb#L201
If this is not working yet but you are successfully showing the external images in the onebox, my hunch is the images don’t meet the criteria to be uploaded.