Awesome, this is actually a great way to get some coding practice
To solve this you will need to fork GitHub - discourse/onebox: (DEPRECATED) A gem for turning URLs into website previews · GitHub and add your changes there. They have actually a pretty nice tutorial on how to add a new onebox provider in the README.
To solve this issue I would actually do it in two steps:
- Make sure the existing image onebox located at
lib/onebox/engine/image_onebox.rbdoes not loadcommons.wikimedia.orgURLs anymore. That could be done by modifying the regular expression inmatches_regexp - Add a new
wikimedia_onebox.rbprovider, which does first parse the provided URL and then makes a request to the Wikipedia API to get the actual image URL. Take a look at the tutorial in the README and the existing oneboxes inlib/onebox/engine/i. For the Wikimedia part you can reuse some of the code I linked above.
I have only played around with it a little myself. But you will need some way to test your work, and when I actually began implementing a onebox I wrote myself a helper script in the root directory of the onebox source code which looked something like this:
require_relative "lib/onebox"
# Set this path to your actual template path
Onebox.options = {
load_paths: [
File.join(File.dirname(__FILE__), "templates")
]
}
# This is the URL to test:
url = "https://commons.wikimedia.org/wiki/File:Stones_members_montage2.jpg"
# Create the onebox for the URL:
preview = Onebox.preview(url)
# This will print the generated onebox HTML:
puts preview