From 515fd8a4c32a356a005510fe4a11ce0f976dda27 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Mon, 21 Jun 2021 09:33:12 -0400 Subject: [PATCH] DEV: Change method used to reference custom font assets (#13446) The `asset-url` helper has been deprecated. --- lib/stylesheet/importer.rb | 3 ++- spec/components/stylesheet/importer_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/stylesheet/importer.rb b/lib/stylesheet/importer.rb index 7826354e26d..e323f38f3c6 100644 --- a/lib/stylesheet/importer.rb +++ b/lib/stylesheet/importer.rb @@ -213,8 +213,9 @@ module Stylesheet contents = +"" if font[:variants].present? + fonts_dir = UrlHelper.absolute("#{Discourse.base_path}/fonts") font[:variants].each do |variant| - src = variant[:src] ? variant[:src] : "asset-url(\"/fonts/#{variant[:filename]}?v=#{DiscourseFonts::VERSION}\") format(\"#{variant[:format]}\")" + src = variant[:src] ? variant[:src] : "url(\"#{fonts_dir}/#{variant[:filename]}?v=#{DiscourseFonts::VERSION}\") format(\"#{variant[:format]}\")" contents << <<~EOF @font-face { font-family: #{font[:name]}; diff --git a/spec/components/stylesheet/importer_spec.rb b/spec/components/stylesheet/importer_spec.rb index 6ddc9ba04c0..4e9a0f8c117 100644 --- a/spec/components/stylesheet/importer_spec.rb +++ b/spec/components/stylesheet/importer_spec.rb @@ -61,6 +61,13 @@ describe Stylesheet::Importer do expect(compile_css("desktop")) .to include(":root{--font-family: #{base_font[:stack]}}") .and include(":root{--heading-font-family: #{heading_font[:stack]}}") + + set_cdn_url("http://cdn.localhost") + + # uses CDN and includes cache-breaking param + expect(compile_css("mobile")) + .to include("http://cdn.localhost/fonts/#{base_font[:variants][0][:filename]}?v=#{DiscourseFonts::VERSION}") + .and include("http://cdn.localhost/fonts/#{heading_font[:variants][0][:filename]}?v=#{DiscourseFonts::VERSION}") end it "includes all fonts in wizard" do