mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:15:05 +08:00
FEATURE: adds emoji search aliases
This commit is contained in:
parent
83c79af980
commit
691174fa8f
|
@ -1,4 +1,4 @@
|
|||
import { emojis, aliases, translations, tonableEmojis } from 'pretty-text/emoji/data';
|
||||
import { emojis, aliases, searchAliases, translations, tonableEmojis } from 'pretty-text/emoji/data';
|
||||
|
||||
// bump up this number to expire all emojis
|
||||
export const IMAGE_VERSION = "<%= Emoji::EMOJI_VERSION %>";
|
||||
|
@ -94,24 +94,28 @@ export function emojiSearch(term, options) {
|
|||
if (results.indexOf(val) === -1) {
|
||||
results.push(val);
|
||||
}
|
||||
return maxResults > 0 && results.length >= maxResults;
|
||||
}
|
||||
|
||||
// if term matches from beginning
|
||||
for (let i=0; i<toSearch.length; i++) {
|
||||
const item = toSearch[i];
|
||||
if (item.indexOf(term) === 0) addResult(item);
|
||||
}
|
||||
|
||||
if (searchAliases[term]) {
|
||||
results.push.apply(results, searchAliases[term]);
|
||||
}
|
||||
|
||||
for (let i=0; i<toSearch.length; i++) {
|
||||
const item = toSearch[i];
|
||||
if (item.indexOf(term) === 0 && addResult(item)) {
|
||||
return results;
|
||||
}
|
||||
if (item.indexOf(term) > 0) addResult(item);
|
||||
}
|
||||
|
||||
for (let i=0; i<toSearch.length; i++) {
|
||||
const item = toSearch[i];
|
||||
if (item.indexOf(term) > 0 && addResult(item)) {
|
||||
return results;
|
||||
}
|
||||
if (maxResults === -1) {
|
||||
return results;
|
||||
} else {
|
||||
return results.slice(0, maxResults);
|
||||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
export function isSkinTonableEmoji(term) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
export const emojis = <%= Emoji.standard.map(&:name).flatten.inspect %>;
|
||||
export const tonableEmojis = <%= Emoji.tonable_emojis.flatten.inspect %>;
|
||||
export const aliases = <%= Emoji.aliases.inspect.gsub("=>", ":") %>;
|
||||
export const searchAliases = <%= Emoji.searchAliases.inspect.gsub("=>", ":") %>;
|
||||
export const translations = {
|
||||
':)' : 'slight_smile',
|
||||
':-)' : 'slight_smile',
|
||||
|
|
|
@ -25,6 +25,10 @@ class Emoji
|
|||
Discourse.cache.fetch(cache_key("aliases_emojis")) { db['aliases'] }
|
||||
end
|
||||
|
||||
def self.searchAliases
|
||||
Discourse.cache.fetch(cache_key("search_aliases_emojis")) { db['searchAliases'] }
|
||||
end
|
||||
|
||||
def self.custom
|
||||
Discourse.cache.fetch(cache_key("custom_emojis")) { load_custom }
|
||||
end
|
||||
|
@ -59,7 +63,7 @@ class Emoji
|
|||
end
|
||||
|
||||
def self.clear_cache
|
||||
%w{custom standard aliases all tonable}.each do |key|
|
||||
%w{custom standard aliases search_aliases all tonable}.each do |key|
|
||||
Discourse.cache.delete(cache_key("#{key}_emojis"))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6795,5 +6795,17 @@
|
|||
"face_vomiting": [
|
||||
"puke"
|
||||
]
|
||||
},
|
||||
"searchAliases": {
|
||||
"sad": [
|
||||
"frowning_face",
|
||||
"slightly_frowning_face",
|
||||
"sob",
|
||||
"crying_cat_face",
|
||||
"cry"
|
||||
],
|
||||
"cry": [
|
||||
"sob"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -12,6 +12,17 @@ EMOJI_IMAGES_PATH ||= "public/images/emoji"
|
|||
|
||||
EMOJI_ORDERING_URL ||= "http://www.unicode.org/emoji/charts/emoji-ordering.html"
|
||||
|
||||
# Format is search pattern => associated emojis
|
||||
# eg: "cry" => [ "sob" ]
|
||||
# for a "cry" query should return: cry and sob
|
||||
SEARCH_ALIASES ||= {
|
||||
"sad" => [ "frowning_face", "slightly_frowning_face", "sob", "crying_cat_face", "cry" ],
|
||||
"cry" => [ "sob" ]
|
||||
}
|
||||
|
||||
# emoji aliases are actually created as images
|
||||
# eg: "right_anger_bubble" => [ "anger_right" ]
|
||||
# your app will physically have right_anger_bubble.png and anger_right.png
|
||||
EMOJI_ALIASES ||= {
|
||||
"right_anger_bubble" => [ "anger_right" ],
|
||||
"ballot_box" => [ "ballot_box_with_ballot" ],
|
||||
|
@ -508,7 +519,8 @@ def write_db_json(emojis)
|
|||
db = {
|
||||
"emojis" => emojis_without_tones,
|
||||
"tonableEmojis" => emoji_with_tones,
|
||||
"aliases" => EMOJI_ALIASES
|
||||
"aliases" => EMOJI_ALIASES,
|
||||
"searchAliases" => SEARCH_ALIASES
|
||||
}
|
||||
|
||||
File.write(EMOJI_DB_PATH, JSON.pretty_generate(db))
|
||||
|
|
Loading…
Reference in New Issue
Block a user