mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-21 21:57:19 +00:00
Update icon downloading code
This commit is contained in:
parent
21ebc04557
commit
37572b4c61
|
@ -18,29 +18,39 @@ def download_material_icon(icon, weight: 400, filled: false, size: 20)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_used_icons
|
def find_used_icons
|
||||||
icons = Set.new
|
icons_by_weight_and_size = {}
|
||||||
|
|
||||||
Dir[Rails.root.join('app', 'javascript', '**', '*.*sx')].map do |path|
|
Dir[Rails.root.join('app', 'javascript', '**', '*.*s*')].map do |path|
|
||||||
File.open(path, 'r') do |file|
|
File.open(path, 'r') do |file|
|
||||||
pattern = %r{\Aimport .* from '@material-symbols/svg-600/outlined/(?<icon>[^-]*)(?<fill>-fill)?.svg';}
|
pattern = %r{\Aimport .* from 'mastodon/../material-icons/(?<weight>[0-9]+)-(?<size>[0-9]+)px/(?<icon>[^-]*)(?<fill>-fill)?.svg';}
|
||||||
file.each_line do |line|
|
file.each_line do |line|
|
||||||
match = pattern.match(line)
|
match = pattern.match(line)
|
||||||
next if match.blank?
|
next if match.blank?
|
||||||
|
|
||||||
icons << match['icon']
|
weight = match['weight'].to_i
|
||||||
|
size = match['size'].to_i
|
||||||
|
|
||||||
|
icons_by_weight_and_size[weight] ||= {}
|
||||||
|
icons_by_weight_and_size[weight][size] ||= Set.new
|
||||||
|
|
||||||
|
icons_by_weight_and_size[weight][size] << match['icon']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
icons
|
icons_by_weight_and_size
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :icons do
|
namespace :icons do
|
||||||
desc 'Download used Material Symbols icons'
|
desc 'Download used Material Symbols icons'
|
||||||
task download: :environment do
|
task download: :environment do
|
||||||
find_used_icons.each do |icon|
|
find_used_icons.each do |weight, icons_by_size|
|
||||||
download_material_icon(icon)
|
icons_by_size.each do |size, icons|
|
||||||
download_material_icon(icon, filled: true)
|
icons.each do |icon|
|
||||||
|
download_material_icon(icon, weight: weight, size: size)
|
||||||
|
download_material_icon(icon, weight: weight, size: size, filled: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue