Embedding oneboxes outside of Discourse

Tags: #<Tag:0x00007fe3d156ee08> #<Tag:0x00007fe3d156eae8> #<Tag:0x00007fe3d156e818>


I find oneboxes to be a great way to quickly summarize things. After all, that’s what it was made for. I would like to utilize their full power outside of Discourse, primarily in my Blogger blog.

There is a gem for generating oneboxes, but the MB oneboxes are from a Discourse plug-in:

Is it possible to generate a onebox without setting up an entire Discourse instance, or ideally not anything at all? Even if you did, would it possible to copy it outside of Discourse?


Not sure about this. The oneboxes themselves are implemented using https://github.com/discourse/onebox , and that is designed to be reusable. But the implementation makes some use of Discourse features for handling templates, stylesheets and settings. So while most of the code should be reusable, it will likely need some changes when used outside of Discourse.

I originally wanted them to behave independently from Discourse, but as Discourse already provides a predefined environment with some assumptions about paths it was just easier to rely on this.

I won’t have the time to work on this, but if you want to take a look patches are welcome.


I looked at the code again, actually it shouldn’t be too hard to reuse this. There is only a single line of code inside the oneboxes that is really discourse specific, everything else is just setup in plugin.rb:

  • The templates are normal Mustache templates as the onebox module uses them. The only thing one has to do is configure the path to the template directory, as done in https://github.com/phw/discourse-musicbrainz-onebox/blob/master/plugin.rb#L20
  • You have to include the stylesheet. The only special thing here is that it is a SASS stylesheet. Discourse handles that automatically, but you might need to convert it to CSS first
  • The only Discourse specific thing inside the onebox code is the setting in wikimedia_image.rb. That needs to be refactored, best would be tok inject the settings instead of hardcoding it here.


Thanks for the help! I don’t really have the time to look at this either, but I’ll report back if I do.


I got this working somehow! Code here. And here’s my blog, if you wanted to see how it looked in Blogger. Swedish only, though :slight_smile:

Thanks again for your notes, couldn’t have done it without them!


Cool, great you got it working. I don’t seen any special handling for the third issue above, I would have expected this causes some exceptions.

I could probably clean this up and put the oneboxes elements into a separate gem for easier use, but right now I don’t feel like I’ll have the time for this :frowning:


Yeah, I thought that I would just leave it until it caused any problems, but it never did, at least not for my use case. It looks like it’s used for fetching Wikimedia images, but this URL works fine for example. So I never figured that out.