Skip to content

Commit b0d3bf5

Browse files
committed
better parse a json file than scrape a css one
1 parent 4da3c74 commit b0d3bf5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

support/characterize.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424
out.puts " \\ }"
2525
out.puts
2626

27-
out.puts 'let s:nerdfonts = {'
2827
nerdfonts = Hash.new { |h, k| h[k] = [] }
29-
URI.open(ARGV.first || 'https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/css/nerd-fonts-generated.css') do |f|
30-
f.read.scan(/\.([\w-]*):before {\s*content: "\\(\w*)";\s*}/) { |classname,codepoint|
31-
nerdfonts[codepoint] << classname
32-
}
33-
nerdfonts.sort_by { |(k, v)| k.to_i(16) }.each do |(code, names)|
34-
out.puts " \\ 0x#{code}: [" + names.map { |n| "'#{n}'" }.join(', ') + '],'
28+
URI.open(ARGV[1] || 'https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/glyphnames.json') do |f|
29+
JSON.parse(f.read).each do |(name, subkey)|
30+
code = subkey['code']
31+
next unless code
32+
nerdfonts[code] << "nf-#{name}"
3533
end
3634
end
35+
out.puts 'let s:nerdfonts = {'
36+
nerdfonts.sort_by { |(k, v)| k.to_i(16) }.each do |(code, names)|
37+
out.puts " \\ 0x#{code}: [" + names.map { |n| "'#{n}'" }.join(', ') + '],'
38+
end
3739
out.puts " \\ }"
3840
out.puts
3941

0 commit comments

Comments
 (0)