From db534d67fbf78b71f5fab4be226971334965f2f8 Mon Sep 17 00:00:00 2001 From: Alda Vigdis Skarphedinsdottir <191583+aldavigdis@users.noreply.github.com> Date: Wed, 8 Feb 2023 16:14:15 +0100 Subject: [PATCH] Adding support for unknown browsers/crawlers (#3) Some things only want JPEGs because they are old, clunky and awful like LinkedIn. --- .rubocop.yml | 2 ++ lib/jpg_or_webp.rb | 1 + spec/jpg_or_webp_spec.rb | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 186c943..0945548 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,3 +5,5 @@ Style/Documentation: Enabled: false Metrics/BlockLength: Max: 30 + Exclude: + - 'spec/*' diff --git a/lib/jpg_or_webp.rb b/lib/jpg_or_webp.rb index 43bebaf..792b095 100644 --- a/lib/jpg_or_webp.rb +++ b/lib/jpg_or_webp.rb @@ -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') diff --git a/spec/jpg_or_webp_spec.rb b/spec/jpg_or_webp_spec.rb index 321a750..891ea68 100644 --- a/spec/jpg_or_webp_spec.rb +++ b/spec/jpg_or_webp_spec.rb @@ -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 ' \