FIX: Show background images for both slug formats

It seems there was a discrepancy in that background images were attached
to the full slug category class: `category-:slug-:id` and our body class
only had `category-:slug`.

This fix adds support for both formats.
This commit is contained in:
Robin Ward 2020-07-17 13:42:30 -04:00
parent db9162610a
commit 8e3f667d7c
2 changed files with 3 additions and 3 deletions

View File

@ -192,7 +192,7 @@ module Stylesheet
end end
def category_css(category) def category_css(category)
"body.category-#{category.full_slug} { background-image: url(#{upload_cdn_path(category.uploaded_background.url)}) }\n" "body.category-#{category.slug}, body.category-#{category.full_slug} { background-image: url(#{upload_cdn_path(category.uploaded_background.url)}) }\n"
end end
def to_scss_variable(name, value) def to_scss_variable(name, value)

View File

@ -15,10 +15,10 @@ describe Stylesheet::Importer do
background = Fabricate(:upload) background = Fabricate(:upload)
category = Fabricate(:category, uploaded_background: background) category = Fabricate(:category, uploaded_background: background)
expect(compile_css("category_backgrounds")).to include("body.category-#{category.full_slug}{background-image:url(#{background.url})}") expect(compile_css("category_backgrounds")).to include("body.category-#{category.slug},body.category-#{category.full_slug}{background-image:url(#{background.url})}")
GlobalSetting.stubs(:cdn_url).returns("//awesome.cdn") GlobalSetting.stubs(:cdn_url).returns("//awesome.cdn")
expect(compile_css("category_backgrounds")).to include("body.category-#{category.full_slug}{background-image:url(//awesome.cdn#{background.url})}") expect(compile_css("category_backgrounds")).to include("body.category-#{category.slug},body.category-#{category.full_slug}{background-image:url(//awesome.cdn#{background.url})}")
end end
it "applies S3 CDN to background category images" do it "applies S3 CDN to background category images" do