Skip to content

Commit

Permalink
Adding support for unknown browsers/crawlers
Browse files Browse the repository at this point in the history
Some things only want JPEGs because they are old, clunky and awful like LinkedIn.
  • Loading branch information
aldavigdis committed Feb 8, 2023
1 parent eceb33d commit abfc6be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Style/Documentation:
Enabled: false
Metrics/BlockLength:
Max: 30
Exclude:
- 'spec/*'
1 change: 1 addition & 0 deletions lib/jpg_or_webp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def initialize(user_agent = DEFAULT_USER_AGENT)
end

def image_format
return 'jpg' if @browser.unknown?
return 'jpg' if @browser.ie?
return 'jpg' if @browser.safari? && @browser.platform.mac?('<11.6')
return 'jpg' if @browser.platform.ios?('<14')
Expand Down
8 changes: 8 additions & 0 deletions spec/jpg_or_webp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
expect(j.image_format).to eq('jpg')
end

it 'sends JPEGs to the LinkedIn crawler' do
j = JpgOrWebp.new(
'LinkedInBot/1.0 (compatible; Mozilla/5.0; ' \
'Apache-HttpClient +http://www.linkedin.com)'
)
expect(j.image_format).to eq('jpg')
end

it 'assumes a recent version of Chrome prefers WebP' do
j = JpgOrWebp.new(
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' \
Expand Down

0 comments on commit abfc6be

Please sign in to comment.