-
Notifications
You must be signed in to change notification settings - Fork 166
Subset fonts to used character data #10655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
757d6db
49c1c90
7e7fa4d
a65fef5
24620e7
f498c7f
aebf6ee
ad920a8
253ec84
fcbc46b
1f5f81c
8755a93
ec92027
77daeda
675e0de
bf89353
a643ddc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| !"#$%&'(),-./0123456789:;>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ «»¿ÀÁÈÉÊÎÓÚàáâãçèéêëíîïñóôùúû ‑—‘’“”…‹中体文简 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'pathname' | ||
| require_relative '../config/environment' | ||
|
|
||
| excluded_locales = [] | ||
| excluded_gem_paths = [] | ||
| OptionParser.new do |opts| | ||
| opts.banner = <<~TXT | ||
| Usage | ||
| ======================= | ||
|
|
||
| #{$PROGRAM_NAME} [OPTIONS] | ||
|
|
||
| Prints all unique characters from Rails loaded I18n data, which can be used in combination | ||
| with font subsetting to optimize font sizes. | ||
|
|
||
| TXT | ||
|
|
||
| opts.on('--exclude-locale=LOCALE', 'Disregard characters from the given locale') do |locale| | ||
| excluded_locales << locale.to_sym | ||
| end | ||
|
|
||
| opts.on('--exclude-gem-path=GEM', 'Disregard characters loaded by the given gem') do |gem| | ||
| excluded_gem_paths << Gem.loaded_specs[gem].full_gem_path | ||
| end | ||
|
|
||
| opts.on('-h', '--help', 'Prints this help') do | ||
| STDOUT.puts opts | ||
| exit | ||
| end | ||
| end.parse!(ARGV) | ||
|
|
||
| def sanitize(string) | ||
| string.gsub(/<.+?>/, '').gsub(/%{.+?}/, '').gsub(/[\n\r\t]/, '') | ||
| end | ||
|
|
||
| def hash_values(hash) | ||
| hash.values.flat_map do |value| | ||
| case value | ||
| when Hash | ||
| hash_values(value) | ||
| when Array | ||
| value | ||
| else | ||
| [value] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| I18n.load_path.reject! do |load_path| | ||
| excluded_gem_paths.any? { |gem_path| load_path.start_with?(gem_path) } | ||
| end | ||
|
|
||
| I18n.backend.eager_load! | ||
|
|
||
| data = I18n.backend.translations.slice(*I18n.available_locales - excluded_locales) | ||
|
Comment on lines
+56
to
+58
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO we should do something similar to this in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense to me to add that there |
||
| strings = hash_values(data) | ||
| joined_string = strings.join('') | ||
| sanitized_string = sanitize(joined_string) | ||
| characters = sanitized_string.chars.to_a.uniq.sort.join('') | ||
|
|
||
| STDOUT.puts characters | ||
Uh oh!
There was an error while loading. Please reload this page.