Skip to content
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

Twemoji15.0 #59

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"markdown-it": "12.3.2",
"markdown-it-anchor": "8.4.1",
"matter-js": "0.18.0",
"memoji": "mei23/memoji#15.0.0",
"mfm-js": "groundpolis/gpfm.js",
"ms": "2.1.3",
"multer": "1.4.5-lts.1",
Expand Down Expand Up @@ -243,7 +244,7 @@
"tmp": "0.2.1",
"ts-loader": "9.4.1",
"ts-node": "10.9.1",
"twemoji-parser": "14.0.0",
"twemoji-parser": "git+https://github.com/mei23/twemoji-parser.git#15.0.1",
"typeorm": "0.2.30",
"typescript": "4.9.3",
"ulid": "2.3.0",
Expand Down
3,637 changes: 1,855 additions & 1,782 deletions src/emojilist.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/misc/emoji-regex.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const twemojiRegex = require('twemoji-parser/dist/lib/regex').default;

export const emojiRegex = new RegExp(`(${twemojiRegex.source})`);

export const emojiRegexWithCustom = new RegExp(`(${emojiRegex.source}|:[0-9A-Za-z_]+:)`, 'g');

// Ninja catなどTwemojiを迂回させたいもの
export const vendorEmojiRegex = /(\uD83D\uDC31\u200D(?:\uD83D\uDC64|\uD83D\uDE80|\uD83D\uDC53|\uD83D\uDCBB|\uD83D\uDC09|\uD83C\uDFCD))/;
6 changes: 5 additions & 1 deletion src/misc/twemoji-base.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const twemojiSvgBase = 'https://twemoji.maxcdn.com/v/latest/svg';
// Self hosting
//export const twemojiSvgBase = '/twemoji';

// CDN
export const twemojiSvgBase = 'https://cdn.jsdelivr.net/gh/mei23/memoji@15.0.0/dist/svg';
16 changes: 16 additions & 0 deletions src/server/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ router.get('/apple-touch-icon.png', async ctx => {
});
});

router.get('/twemoji/(.*)', async ctx => {
const path = ctx.path.replace('/twemoji/', '');

if (!path.match(/^[0-9a-f-]+\.svg$/)) {
ctx.status = 404;
return;
}

ctx.set('Content-Security-Policy', `default-src 'none'; style-src 'unsafe-inline'`);

await send(ctx as any, path, {
root: `${__dirname}/../../../node_modules/memoji/dist/svg/`,
maxage: ms('30 days'),
});
});

// ServiceWorker
router.get('/sw.js', async ctx => {
await send(ctx as any, `/assets/sw.${config.version}.js`, {
Expand Down
54 changes: 54 additions & 0 deletions src/tools/dev/emoji2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable node/no-unpublished-require */
// JSONのテンプレ作るスクリプト

export const data = `face 1FAE8 shaking face
symbols 1FA77 pink heart
symbols 1FA75 light blue heart
symbols 1FA76 grey heart
people 1FAF7 leftwards pushing hand
people 1FAF8 rightwards pushing hand
animals_and_nature 1FACE moose
animals_and_nature 1FACF donkey
animals_and_nature 1FABD wing
animals_and_nature 1F426 200D 2B1B black bird
animals_and_nature 1FABF goose
animals_and_nature 1FABC jellyfish
animals_and_nature 1FABB hyacinth
food_and_drink 1FADA ginger root
food_and_drink 1FADB pea pod
objects 1FAAD folding hand fan
objects 1FAAE hair pick
activity 1FA87 maracas
activity 1FA88 flute
symbols 1FAAF khanda
symbols 1F6DC wireless`;

for (const line of data.split(/\n/)) {
const m = line.match(/^([0-9A-Za-z_]+)\t([0-9A-Fa-f ]+)\t([0-9A-Za-z ]+)$/);
if (!m) throw `unmatch ${line}`;

// emojilist.json
const codes = m[2].split(/ /).map(x => parseInt(x, 16));
const char = String.fromCodePoint(...codes);
//console.log(codes);
//console.log(m[1].split(/ /).map(x => String.fromCharCode(parseInt(x, 16))).join());
//console.log(`${char} -- ${m[1]} -- ${m[3]}`);

const obj = {
category: m[1],
char,
name: m[3].replace(/ /g, '_'),
keywords: [],
};

console.log(` ${JSON.stringify(obj)},`);

// twemoji-parser:emoji.yml
/*
const twemojiCode = m[2].split(/ /).map(x => x.toLowerCase()).join('-');
const tw = ` - unicode: "${twemojiCode}"
description: "${m[3]}"
keywords: ""`;
console.log(tw);
*/
}
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6643,6 +6643,10 @@ media-typer@0.3.0:
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=

memoji@mei23/memoji#15.0.0:
version "15.0.0"
resolved "https://codeload.github.com/mei23/memoji/tar.gz/5ebfbda27b2bf38f99cb562ee3cece7d13c55154"

memorystream@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2"
Expand Down Expand Up @@ -10326,11 +10330,15 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=

twemoji-parser@14.0.0, twemoji-parser@14.0.x:
twemoji-parser@14.0.x:
version "14.0.0"
resolved "https://registry.yarnpkg.com/twemoji-parser/-/twemoji-parser-14.0.0.tgz#13dabcb6d3a261d9efbf58a1666b182033bf2b62"
integrity sha512-9DUOTGLOWs0pFWnh1p6NF+C3CkQ96PWmEFwhOVmT3WbecRC+68AIqpsnJXygfkFcp4aXbOp8Dwbhh/HQgvoRxA==

"twemoji-parser@git+https://github.com/mei23/twemoji-parser.git#15.0.1":
version "15.0.1"
resolved "git+https://github.com/mei23/twemoji-parser.git#d374b2f54efaf3ecf21948daecf851b69c9a7d62"

type-check@^0.4.0, type-check@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"
Expand Down