Skip to content

Commit 5f39b6f

Browse files
committed
Minor fix.3
1 parent 4d89230 commit 5f39b6f

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

_plugins/download-3rd-party.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
font_file_types = ['otf', 'ttf', 'woff', 'woff2']
1010
image_file_types = ['.gif', '.jpg', '.jpeg', '.png', '.webp']
1111

12-
def download_and_change_rule_set_url(rule_set, rule, dest, dirname, config, file_types)
12+
def download_and_change_rule_set_url(rule_set, rule, dest, dirname, config, file_types, base_url = nil)
1313
# check if the rule has a url
1414
if rule_set[rule].include?('url(')
1515
# get the file url
@@ -25,8 +25,14 @@ def download_and_change_rule_set_url(rule_set, rule, dest, dirname, config, file
2525
# verify if the file is of the correct type
2626
if file_name.end_with?(*file_types)
2727
# fix the url if it is not an absolute url
28-
unless url.start_with?('https://')
29-
url = URI.join(url, url).to_s
28+
unless url.start_with?('https://') || url.start_with?('http://')
29+
if base_url
30+
url = URI.join(base_url, url).to_s
31+
else
32+
# Skip if we can't resolve relative URL and no base URL provided
33+
puts "Warning: Skipping relative URL #{url} - no base URL provided"
34+
return
35+
end
3036
end
3137

3238
# download the file
@@ -155,7 +161,7 @@ def download_fonts_from_css(config, url, dest, lib_name, file_types)
155161
# get the font-face rules
156162
css.each_rule_set do |rule_set|
157163
# check if the rule set has a url
158-
download_and_change_rule_set_url(rule_set, 'src', File.join(dest, 'fonts'), File.join(lib_name, 'fonts'), config, file_types)
164+
download_and_change_rule_set_url(rule_set, 'src', File.join(dest, 'fonts'), File.join(lib_name, 'fonts'), config, file_types, url)
159165
end
160166

161167
# save the modified css file

0 commit comments

Comments
 (0)