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