Auto fetch emoji list
This commit is contained in:
parent
5077d09594
commit
2900823554
|
@ -2,3 +2,5 @@ elm-stuff
|
|||
target
|
||||
js/*
|
||||
!js/main.min.js
|
||||
elm/Emoji.elm
|
||||
emoji.txt
|
||||
|
|
12
Makefile
12
Makefile
|
@ -15,13 +15,13 @@ BUILD_DIR=js
|
|||
dev: target/debug/elmojinput
|
||||
release: target/release/elmojinput
|
||||
|
||||
js/main.js: elm/**
|
||||
js/main.js: elm/** elm/Emoji.elm
|
||||
$(ELM) make elm/Main.elm --output $(BUILD_DIR)/main.js
|
||||
|
||||
js/main.min.js: js/main.tmp.js
|
||||
@$(UGLIFYJS) $(BUILD_DIR)/main.tmp.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | $(UGLIFYJS) --mangle > $(BUILD_DIR)/main.min.js
|
||||
|
||||
js/main.tmp.js: elm/**
|
||||
js/main.tmp.js: elm/** elm/Emoji.elm
|
||||
@$(ELM) make elm/Main.elm --optimize --output $(BUILD_DIR)/main.tmp.js
|
||||
|
||||
target/debug/elmojinput: js/main.js src/**
|
||||
|
@ -30,5 +30,11 @@ target/debug/elmojinput: js/main.js src/**
|
|||
target/release/elmojinput: js/main.min.js src/**
|
||||
cargo build --release
|
||||
|
||||
js/emoji.txt:
|
||||
@curl https://unicode.org/Public/emoji/14.0/emoji-test.txt -o $(BUILD_DIR)/emoji.txt
|
||||
|
||||
elm/Emoji.elm: js/emoji.txt extract.js
|
||||
@node extract.js > elm/Emoji.elm
|
||||
|
||||
clean:
|
||||
@rm -rf $(BUILD_DIR)/{main.js,main.min.js}
|
||||
@rm -rf $(BUILD_DIR)/{main.js,main.min.js,emoji.txt} elm/Emoji.elm
|
||||
|
|
1525
elm/Emoji.elm
1525
elm/Emoji.elm
File diff suppressed because it is too large
Load Diff
52
elm/Main.elm
52
elm/Main.elm
|
@ -9,7 +9,7 @@ import Html
|
|||
import Html.Attributes
|
||||
import Html.Events
|
||||
import Json.Decode as Decode
|
||||
import Levenshtein
|
||||
import Levenshtein exposing (distance)
|
||||
|
||||
|
||||
main =
|
||||
|
@ -58,15 +58,16 @@ modelEmojis model =
|
|||
|
||||
Search s ->
|
||||
Emoji.categories
|
||||
|> List.concatMap Emoji.getEmojis
|
||||
|> List.map (\x -> ( x, minimum ( Levenshtein.distance s x.name, List.map (\v -> Levenshtein.distance s v + 1) x.tags ) ))
|
||||
|> List.sortBy Tuple.second
|
||||
|> List.map Emoji.getEmojis
|
||||
|> doubleMap (\x -> ( x, distance s x.name ))
|
||||
|> List.map (List.sortBy Tuple.second)
|
||||
|> mergeBy Tuple.second
|
||||
|> List.map Tuple.first
|
||||
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init _ =
|
||||
( Category Emoji.Recent, Cmd.none )
|
||||
( Category Emoji.Smileys, Cmd.none )
|
||||
|
||||
|
||||
type Msg
|
||||
|
@ -236,3 +237,44 @@ onEnter msg =
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
mergeAux : (a -> comparable) -> List a -> List a -> List a
|
||||
mergeAux comparator listOne listTwo =
|
||||
case ( listOne, listTwo ) of
|
||||
( _, [] ) ->
|
||||
listOne
|
||||
|
||||
( [], _ ) ->
|
||||
listTwo
|
||||
|
||||
( frontOne :: restOne, frontTwo :: restTwo ) ->
|
||||
if comparator frontOne < comparator frontTwo then
|
||||
frontOne :: mergeAux comparator restOne listTwo
|
||||
|
||||
else
|
||||
frontTwo :: mergeAux comparator listOne restTwo
|
||||
|
||||
|
||||
mergeBy : (a -> comparable) -> List (List a) -> List a
|
||||
mergeBy comparator input =
|
||||
case input of
|
||||
[] ->
|
||||
[]
|
||||
|
||||
[ [] ] ->
|
||||
[]
|
||||
|
||||
[ a ] ->
|
||||
a
|
||||
|
||||
[ a, b ] ->
|
||||
mergeAux comparator a b
|
||||
|
||||
a :: b :: t ->
|
||||
mergeBy comparator (mergeAux comparator a b :: t)
|
||||
|
||||
|
||||
doubleMap : (a -> b) -> List (List a) -> List (List b)
|
||||
doubleMap map input =
|
||||
List.map (\x -> List.map map x) input
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
const fs = require('fs');
|
||||
|
||||
function formatEmoji(emoji) {
|
||||
return ('{ name = "' + emoji.name + '", unicode = "' + emoji.unicode + '" }');
|
||||
}
|
||||
|
||||
let text = fs.readFileSync('js/emoji.txt', 'utf-8');
|
||||
let emojis = {};
|
||||
let currentEmojis = null;
|
||||
|
||||
for (let line of text.split('\n')) {
|
||||
if (line.startsWith('#')) {
|
||||
if (line.startsWith('# group:')) {
|
||||
let name = line.split(':')[1].split(' ')[1].toLowerCase();
|
||||
emojis[name] = [];
|
||||
currentEmojis = emojis[name];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let end = line.split('#')[1];
|
||||
let split = end.split(' ');
|
||||
let emoji = split[1];
|
||||
let name = split.slice(3).join(' ');
|
||||
currentEmojis.push({
|
||||
name,
|
||||
unicode: emoji,
|
||||
});
|
||||
}
|
||||
|
||||
delete(emojis.component);
|
||||
|
||||
// Generate elm
|
||||
|
||||
console.log('module Emoji exposing (..)');
|
||||
console.log('\n');
|
||||
|
||||
console.log('type alias Emoji =');
|
||||
console.log(' { name : String');
|
||||
console.log(' , unicode : String');
|
||||
console.log(' }');
|
||||
console.log('\n');
|
||||
|
||||
console.log('type alias Emojis =');
|
||||
let first = true;
|
||||
for (let key in emojis) {
|
||||
console.log(' ' + (first ? '{' : ',') + ' ' + key + ' : List Emoji');
|
||||
first = false;
|
||||
}
|
||||
console.log(' }')
|
||||
console.log('\n');
|
||||
|
||||
console.log('type Category');
|
||||
first = true;
|
||||
for (let key in emojis) {
|
||||
console.log(' ' + (first ? '=' : '|') + ' ' + key[0].toUpperCase() + key.slice(1).toLowerCase());
|
||||
first = false;
|
||||
}
|
||||
console.log('\n');
|
||||
|
||||
console.log('categories : List Category');
|
||||
console.log('categories =');
|
||||
console.log(' [' + Object.keys(emojis).map(x => x[0].toUpperCase() + x.slice(1).toLowerCase()).join(', ') + ']');
|
||||
console.log('\n');
|
||||
|
||||
console.log('categoryEmoji : Category -> Emoji');
|
||||
console.log('categoryEmoji category =');
|
||||
console.log(' case category of');
|
||||
|
||||
for (let key in emojis) {
|
||||
console.log(' ' + key[0].toUpperCase() + key.slice(1).toLowerCase() + ' ->');
|
||||
console.log(' ' + formatEmoji(emojis[key][0]) + '\n');
|
||||
}
|
||||
console.log();
|
||||
|
||||
console.log('getEmojis : Category -> List Emoji')
|
||||
console.log('getEmojis category =');
|
||||
console.log(' case category of');
|
||||
|
||||
for (let key in emojis) {
|
||||
console.log(' ' + key[0].toUpperCase() + key.slice(1).toLowerCase() + ' ->');
|
||||
console.log(' emojis.' + key + '\n');
|
||||
}
|
||||
console.log();
|
||||
|
||||
console.log('emojis : Emojis');
|
||||
console.log('emojis =');
|
||||
let first1 = true;
|
||||
|
||||
for (let key in emojis) {
|
||||
console.log(' ' + (first1 ? '{' : ',') + ' ' + key + ' =');
|
||||
let first2 = true;
|
||||
for (let emoji of emojis[key]) {
|
||||
console.log(' ' + (first2 ? '[' : ',') + ' ' + formatEmoji(emoji));
|
||||
first2 = false;
|
||||
}
|
||||
console.log(' ]');
|
||||
first1 = false;
|
||||
}
|
||||
|
||||
console.log(' }');
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue