Fixes #394 and upgrade to emoji 15.1, optimizes size

pull/570/head
Zef Hemel 2023-11-21 12:19:47 +01:00
parent bdb4159f5b
commit db607f1661
5 changed files with 28 additions and 5229 deletions

View File

@ -1,4 +1,4 @@
build: build:
curl https://unicode.org/Public/emoji/14.0/emoji-test.txt > emoji-data.txt curl https://unicode.org/Public/emoji/15.1/emoji-test.txt > emoji-data.txt
node build.js deno run -A build.ts
rm emoji-data.txt rm emoji-data.txt

View File

@ -1,17 +0,0 @@
// Generates emoji.json from emoji-data.txt
const { readFileSync, writeFileSync } = require("fs");
const emojiRe = /#\s([^\s]+)\s+E[^\s]+\s+(.+)$/;
let text = readFileSync("emoji-data.txt", "utf-8");
const lines = text.split("\n").filter((line) => !line.startsWith("#"));
let emoji = [];
for (const line of lines) {
let match = emojiRe.exec(line);
if (match) {
emoji.push([match[1], match[2].toLowerCase().replaceAll(/\W+/g, "_")]);
}
}
writeFileSync("emoji.json", JSON.stringify(emoji));

20
plugs/emoji/build.ts Normal file
View File

@ -0,0 +1,20 @@
// Generates emoji.json from emoji-data.txt
const emojiRe = /#\s([^\s]+)\s+E[^\s]+\s+(.+)$/;
let text = Deno.readTextFileSync("emoji-data.txt");
const lines = text.split("\n").filter((line) => !line.startsWith("#"));
const emojis: string[] = [];
for (const line of lines) {
let match = emojiRe.exec(line);
if (match) {
const emoji = match[1];
const name = match[2].toLowerCase().replaceAll(/\W+/g, "_");
emojis.push(`${name} ${emoji}`);
}
}
Deno.writeFileSync(
"emoji.json",
new TextEncoder().encode(JSON.stringify(emojis.join("|"))),
);

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,8 @@
import emojis from "./emoji.json" assert { type: "json" }; import emojiBlob from "./emoji.json" assert { type: "json" };
import type { CompleteEvent } from "$sb/app_event.ts"; import type { CompleteEvent } from "$sb/app_event.ts";
const emojis = emojiBlob.split("|").map((line) => line.split(" "));
export function emojiCompleter({ linePrefix, pos }: CompleteEvent) { export function emojiCompleter({ linePrefix, pos }: CompleteEvent) {
const match = /:([\w]+)$/.exec(linePrefix); const match = /:([\w]+)$/.exec(linePrefix);
if (!match) { if (!match) {
@ -9,14 +11,14 @@ export function emojiCompleter({ linePrefix, pos }: CompleteEvent) {
const [fullMatch, emojiName] = match; const [fullMatch, emojiName] = match;
const filteredEmoji = emojis.filter(([_, shortcode]) => const filteredEmoji = emojis.filter(([shortcode]) =>
shortcode.includes(emojiName) shortcode.includes(emojiName)
); );
return { return {
from: pos - fullMatch.length, from: pos - fullMatch.length,
filter: false, filter: false,
options: filteredEmoji.map(([emoji, shortcode]) => ({ options: filteredEmoji.map(([shortcode, emoji]) => ({
detail: shortcode, detail: shortcode,
label: emoji, label: emoji,
type: "emoji", type: "emoji",