discourse/plugins/emoji/lib/tasks/emoji.rake

49 lines
12 KiB
Ruby
Raw Normal View History

desc "update emoji images"
task "emoji:update" => :environment do
download_emojis_for("emoji_one", "https://raw.githubusercontent.com/Ranks/emojione/master/assets/png/%s.png", uppercase: true, leading_zeros: true)
download_emojis_for("twitter", "https://raw.githubusercontent.com/twitter/twemoji/gh-pages/72x72/%s.png", lowercase: true)
download_emojis_for("apple", "https://raw.githubusercontent.com/github/gemoji/master/images/emoji/unicode/%s.png", lowercase: true, leading_zeros: true)
# download_google_emojis("https://raw.githubusercontent.com/gjtorikian/NotoColorEmoji-png/master/images/68x64/%s.png")
end
def download_emojis_for(set, url_template, options={})
puts "Downloading emojis for #{set}..."
uppercase = options[:uppercase] == true
lowercase = options[:lowercase] == true
leading_zeros = options[:leading_zeros] == true
Emoji.all.each do |emoji|
codepoints = emoji["emoji"].codepoints.map { |c| c.to_s(16).rjust(leading_zeros ? 4 : 0, '0') }
filename = codepoints.join('-').sub(/-fe0f\b/, '')
filename = filename.downcase if lowercase
filename = filename.upcase if uppercase
puts "#{filename} -> #{emoji["emoji"]}"
url = url_template % filename
data = open(url).read rescue nil
next if data.nil?
emoji["aliases"].each do |name|
File.open("plugins/emoji/public/images/#{set}/#{name}.png", "wb") { |f| f << data }
end
end
end
# extracted from the NotoColorEmoji font
GOOGLE_EMOJIS = {169=>19, 174=>20, 8419=>23, 8482=>25, 8986=>114, 8987=>115, 9193=>806, 9194=>807, 9195=>270, 9196=>271, 9200=>275, 9203=>276, 9729=>86, 9745=>799, 9748=>654, 9749=>655, 9757=>17, 9786=>692, 9800=>702, 9801=>622, 9802=>704, 9803=>705, 9804=>706, 9805=>626, 9806=>708, 9807=>709, 9808=>710, 9809=>711, 9810=>712, 9811=>713, 9851=>714, 9855=>715, 9875=>805, 9888=>816, 9889=>749, 9917=>14, 9918=>15, 9924=>784, 9925=>785, 9934=>786, 9940=>787, 9962=>788, 9970=>789, 9971=>790, 9973=>791, 9978=>792, 9981=>793, 9989=>794, 9994=>795, 9995=>796, 9996=>797, 10024=>798, 10060=>800, 10062=>801, 10067=>802, 10068=>803, 10069=>804, 10133=>810, 10134=>811, 10135=>812, 10160=>814, 10175=>815, 12336=>24, 126980=>1, 127183=>21, 127344=>26, 127345=>27, 127358=>28, 127359=>29, 127374=>30, 127377=>31, 127378=>32, 127379=>33, 127380=>34, 127381=>35, 127382=>36, 127383=>37, 127384=>38, 127385=>39, 127386=>40, 127462=>41, 127463=>42, 127464=>43, 127465=>44, 127466=>45, 127467=>46, 127468=>47, 127469=>48, 127470=>49, 127471=>50, 127472=>51, 127473=>52, 127474=>53, 127475=>54, 127476=>55, 127477=>56, 127478=>57, 127479=>58, 127480=>59, 127481=>60, 127482=>61, 127483=>62, 127484=>63, 127485=>64, 127486=>65, 127487=>66, 127489=>67, 127490=>68, 127514=>69, 127535=>71, 127538=>72, 127539=>73, 127540=>74, 127541=>75, 127542=>76, 127543=>77, 127544=>78, 127545=>79, 127546=>80, 127568=>81, 127569=>82, 127744=>88, 127745=>89, 127746=>90, 127747=>91, 127748=>92, 127749=>93, 127750=>94, 127751=>95, 127752=>96, 127753=>97, 127754=>98, 127755=>99, 127756=>100, 127757=>101, 127758=>102, 127759=>103, 127760=>104, 127761=>105, 127762=>106, 127763=>107, 127764=>108, 127765=>109, 127766=>110, 127767=>111, 127768=>112, 127769=>113, 127770=>84, 127771=>85, 127772=>116, 127773=>117, 127774=>118, 127775=>119, 127776=>120, 127792=>121, 127793=>122, 127794=>123, 127795=>124, 127796=>125, 127797=>126, 127799=>127, 127800=>128, 127801=>129, 127802=>130, 127803=>131, 127804=>132, 127805=>133, 127806=>134, 127807=>135, 127808=>136, 127809=>137, 127810=>138, 127811=>139, 127812=>140, 127813=>141, 127814=>142, 127815=>143, 127816=>144, 127817=>145, 127818=>146, 127819=>147, 127820=>148, 127821=>149, 127822=>150, 127823=>151, 127824=>152, 127825=>153, 127826=>154, 127827=>155, 127828=>156, 127829=>157, 127830=>158, 127831=>159, 127832=>160, 127833=>161, 127834=>162, 127835=>163, 127836=>164, 127837=>165, 127838=>166, 127839=>167, 127840=>168, 127841=>169, 127842=>170, 127843=>171, 127844=>172, 127845=>173, 127846=>174, 127847=>175, 127848=>176, 127849=>177, 127850=>178, 127851=>179, 127852=>180, 127853=>181, 127854=>182, 127855=>183, 127856=>184, 127857=>185, 127858=>186, 127859=>187, 127860=>188, 127861=>189, 127862=>190, 127863=>191, 127864=>192, 127865=>193, 127866=>194, 127867=>195, 127868=>196, 127872=>197, 127873=>198, 127874=>199, 127875=>200, 127876=>201, 127877=>202, 127878=>203, 127879=>204, 127880=>205, 127881=>206, 127882=>207, 127883=>208, 127884=>209, 127885=>210, 127886=>211, 127887=>212, 127888=>213, 127889=>214, 127890=>215, 127891=>216, 127904=>217, 127905=>218, 127906=>219, 127907=>220, 127908=>221, 127909=>222, 127910=>223, 127911=>224, 127912=>225, 127913=>226, 127914=>227, 127915=>228, 127916=>229, 127917=>230, 127918=>231, 127919=>232, 127920=>233, 127921=>234, 127922=>235, 127923=>236, 127924=>237, 127925=>238, 127926=>239, 127927=>240, 127928=>241, 127929=>242, 127930=>243, 127931=>244, 127932=>245, 127933=>246, 127934=>247, 127935=>248, 127936=>249, 127937=>250, 127938=>251, 127939=>252, 127940=>253, 127942=>254, 127943=>255, 127944=>256, 127945=>257, 127946=>258, 127968=>259, 127969=>260, 127970=>261, 127971=>262, 127972=>263, 127973=>264, 127974=>265, 127975=>266, 127976=>267, 127977=>268, 127978=>269, 127979=>808, 127980=>809, 127981=>272, 127982=>273, 127983=>274, 127984=>813, 128000=>277, 128001=>278, 128002=>279, 128003=>280, 128004=>281, 128005=>282, 128006=>283, 128007=>284, 128008=>285, 128009=>286, 128010=>287, 128011=>288, 128012=>289, 128013=>290, 128014=>291, 128015=>292, 128016=>293, 128017=>294, 128018=>295, 128019=>296,
def download_google_emojis(url_template)
puts "Downloading emojis for google..."
Emoji.all.each do |emoji|
codepoint = emoji["emoji"].codepoints.first
filename = GOOGLE_EMOJIS[codepoint]
next if filename.nil?
puts "#{filename} -> #{emoji["emoji"]}"
url = url_template % filename
data = open(url).read rescue nil
next if data.nil?
emoji["aliases"].each do |name|
File.open("plugins/emoji/public/images/google/#{name}.png", "wb") { |f| f << data }
end
end
end