Skip to content

Commit a30a565

Browse files
authored
update emoji (#992)
1 parent 1929b6b commit a30a565

12 files changed

Lines changed: 5975 additions & 9 deletions

File tree

.changeset/violet-buckets-run.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"hyperbook": patch
3+
"@hyperbook/markdown": patch
4+
"hyperbook-studio": patch
5+
---
6+
7+
Update emoji shortcodes.

packages/hyperbook/dev.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ socket.addEventListener("message", (event) => {
6969
try {
7070
// Try to read the given resource into a Buffer.
7171
pathname = decodeURIComponent(pathname);
72-
console.log(pathname);
7372
let resourcePath = path.join(outDir, pathname);
7473
let responseBody: Buffer;
7574
responseBody = await fs.promises

packages/markdown/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
"version": "pnpm build",
3131
"lint": "tsc --noEmit",
3232
"dev": "node devWatcher.mjs",
33-
"dev:build": "node devBuild.mjs && node postbuild.mjs",
33+
"dev:build": "node prebuild.mjs && node devBuild.mjs && node postbuild.mjs",
3434
"test": "vitest",
35-
"build": "rimraf dist && pnpm build:pkg && pnpm build:types && node postbuild.mjs",
35+
"build": "rimraf dist && node prebuild.mjs && pnpm build:pkg && pnpm build:types && node postbuild.mjs",
3636
"build:pkg": "node ../../scripts/build.mjs && ncp assets dist/assets",
3737
"build:types": "tsc --project tsconfig.build.json --declaration --emitDeclarationOnly"
3838
},
@@ -94,6 +94,7 @@
9494
"lunr-languages": "^1.14.0",
9595
"mermaid": "11.6.0",
9696
"ncp": "^2.0.0",
97+
"node-fetch": "^3.3.2",
9798
"p5": "^2.0.1",
9899
"scratchblocks": "^3.6.4",
99100
"vfile": "^6.0.3",

packages/markdown/prebuild.mjs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// scripts/build-emoji-json.ts
2+
import fs from "fs";
3+
import path from "path";
4+
import fetch from "node-fetch";
5+
6+
async function buildEmojiJson() {
7+
const res = await fetch("https://api.github.com/emojis");
8+
const json = await res.json();
9+
const emojiMap = {};
10+
11+
for (const [name, url] of Object.entries(json)) {
12+
const match = url.match(/unicode\/([a-f0-9\-]+)\.png/);
13+
if (match) {
14+
const codepoints = match[1]
15+
.split("-")
16+
.map((cp) => String.fromCodePoint(parseInt(cp, 16)))
17+
.join("\u200D");
18+
emojiMap[name] = codepoints;
19+
}
20+
}
21+
22+
const outputPath = path.join("src/github-emojis.json");
23+
fs.writeFileSync(outputPath, JSON.stringify(emojiMap, null, 2), "utf8");
24+
console.log(
25+
`✅ Saved ${Object.keys(emojiMap).length} emojis to ${outputPath}`,
26+
);
27+
28+
return emojiMap;
29+
}
30+
31+
async function updateDocs(emojiMap) {
32+
const enBase = `---
33+
name: Emoji
34+
permaid: emoji
35+
---
36+
37+
# Emoji
38+
39+
Just like in most chat apps you can insert an emoji by using its name.
40+
41+
\`\`\`md
42+
:smiley: :apple: :penguin:
43+
\`\`\`
44+
45+
:smiley: :apple: :penguin:
46+
`;
47+
48+
const deBase = `---
49+
name: Emoji
50+
permaid: emoji
51+
---
52+
53+
# Emoji
54+
55+
Wie in den meisten Chat-Apps kannst du Emojis durch Eingabe ihres Namens einfügen.
56+
57+
\`\`\`md
58+
:smiley: :apple: :penguin:
59+
\`\`\`
60+
61+
:smiley: :apple: :penguin:
62+
`;
63+
64+
const enHeader = `# GitHub Emoji Cheat Sheet
65+
66+
This file lists all supported GitHub-style emoji shortcodes and their corresponding Unicode characters.
67+
68+
| Emoji | Shortcode |
69+
|:------|:----------|
70+
`;
71+
72+
const deHeader = `# GitHub Emoji Cheat Sheet
73+
Diese Datei listet alle unterstützten GitHub-Emoji-Kürzel und ihre entsprechenden Unicode-Zeichen auf.
74+
75+
| Emoji | Shortcode
76+
|:------|:----------|
77+
`;
78+
79+
const rows = Object.entries(emojiMap)
80+
.sort(([a], [b]) => a.localeCompare(b))
81+
.map(([name, emoji]) => `| ${emoji} | \`:${name}:\` |`)
82+
.join("\n");
83+
84+
fs.writeFileSync(
85+
path.join(
86+
process.cwd(),
87+
"..",
88+
"..",
89+
"website",
90+
"en",
91+
"book",
92+
"elements",
93+
"emoji.md",
94+
),
95+
enBase + "\n" + enHeader + rows + "\n",
96+
"utf8",
97+
);
98+
99+
fs.writeFileSync(
100+
path.join(
101+
process.cwd(),
102+
"..",
103+
"..",
104+
"website",
105+
"de",
106+
"book",
107+
"elements",
108+
"emoji.md",
109+
),
110+
deBase + "\n" + deHeader + rows + "\n",
111+
"utf8",
112+
);
113+
}
114+
115+
buildEmojiJson()
116+
.catch((err) => {
117+
console.error("❌ Failed to fetch and build emoji map", err);
118+
})
119+
.then(updateDocs);

0 commit comments

Comments
 (0)