Everyone one must be quite familiar with Facebook’s share feature that reads the given URL and parses it for META data (title, thumbnails, description etc…) This post deals with exactly that.
The only gem that I could find for this was Pismo. It was quite straight forward to integrate and easy to use and did do the job say 80% of times and that’s good to start of with. You could always add logic and some intelligence to rank better titles, pictures and description as you move ahead. So here we go… I’ll take you through a bit of the integration steps and some sample code to help understand how it works.
- Install the Pismo Gem
Assuming that you have a text box on your page and whenever the user types something in the text box, you check for a valid URL, if found you send a AJAX call that uses Pismo to fetch the data for you as display it on your page. Here is a sample code to guide you through the process:
And that’s it. A very simple example, but it’ll do the trick. Pismo is a wonderful base for an exciting feature like this, a few points that could be worked on to take this one step further:
- Pismo is in initial stages of development and it’s algorithms are not yet perfected. If you are planning to use this on a full fledged production application you might want to fiddle along with their algorithms and add some more intelligence to it. Selecting the best title, image etc… based on words, image size and so on.
- Allow a user to decide what thumbnail they’ll like to use, give them the ability to edit the title etc…
- Pismo allows you to parse through the entire HTML, you could do a lot more than just fetch the title or description.
- A lot of Pismo’s methods are not documented yet. Do take out time to read through the gem and understand how it function.
Hope this helps you get started!
Cheers! Happy Coding.