-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add favicon scraper. Fixes #40
- Loading branch information
Showing
14 changed files
with
101 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'link_thumbnailer/model' | ||
|
||
module LinkThumbnailer | ||
module Models | ||
class Favicon < ::LinkThumbnailer::Model | ||
|
||
attr_reader :uri | ||
|
||
def initialize(uri) | ||
@uri = uri | ||
end | ||
|
||
def to_s | ||
uri.to_s | ||
end | ||
|
||
def as_json(*) | ||
{ | ||
src: to_s | ||
} | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'link_thumbnailer/scrapers/default/base' | ||
require 'link_thumbnailer/models/favicon' | ||
|
||
module LinkThumbnailer | ||
module Scrapers | ||
module Default | ||
class Favicon < ::LinkThumbnailer::Scrapers::Default::Base | ||
|
||
def value | ||
modelize(to_uri(href)).to_s | ||
end | ||
|
||
private | ||
|
||
def to_uri(href) | ||
::URI.parse(href) | ||
rescue ::URI::InvalidURIError | ||
nil | ||
end | ||
|
||
def href | ||
node.attributes['href'].value.to_s if node | ||
end | ||
|
||
def node | ||
document.xpath("//link[contains(@rel, 'icon')]").first | ||
end | ||
|
||
def modelize(uri) | ||
model_class.new(uri) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'link_thumbnailer/scrapers/opengraph/base' | ||
|
||
module LinkThumbnailer | ||
module Scrapers | ||
module Opengraph | ||
class Favicon < ::LinkThumbnailer::Scrapers::Opengraph::Base | ||
|
||
def value | ||
nil | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.