Skip to content

Attributes option explained

gottfrois edited this page Sep 23, 2014 · 5 revisions

Here we will talk about the attributes option. By default LinkThumbnailer set this option to the following value:

config.attributes = [:title, :images, :description, :videos, :favicon]

Each element of the above array is used to tell LinkThumbnailer what to look for on a given website. Here we want LinkThumbnailer to find:

  • A title for the given website
  • images for the given website if any
  • A description for the given website
  • videos for the given website if any
  • The favicon

LinkThumbnailer will do its best to fulfill your requirements by trying to find those attributes using its scrapers. Scrapers are plain old ruby class build inside LinkThumbnailer used to parse the given website HTML content. Currently there are 2 type of scrapers that use 2 different techniques:

  • OpenGraph scraper that will use the OpenGraph protocol
  • Homemade custom scraper that will parse the raw HTML

Title

In order for LinkThumbnailer to find a title, it will look at (in order):

  1. the og:title opengraph attribute
  2. the title html attribute

Images

In order for LinkThumbnailer to find images, it will look at (in order):

  1. the og:images opengraph attribute(s) (LinkThumbnailer can handle multiple og:images attributes)
  2. the img html attribute(s)

Videos

In order for LinkThumbnailer to find videos, it will look at (in order):

  1. the og:videos opengraph attributes(s) (LinkThumbnailer can handle multiple og:videos attributes)

Description

In order for LinkThumbnailer to find a description, it will look at (in order):

  1. the og:description opengraph attribute
  2. the p,td css selectors and will sort them using graders

Favicon

Any link tag in the header that includes the icon string:

<link rel="icon" type="image/x-icon" href="http://foo.com/favicon.ico">
<link rel="shortcut icon" type="image/x-icon" href="http://foo.com/favicon.ico">
<link rel="icon shortcut" type="image/x-icon" href="http://foo.com/favicon.ico">

All the above will match.

Please ask if you want LinkThumbnailer to handle more attributes.