docs/.vitepress/configs/markdown/emoji.ts
281 lines · 10499 bytes
1/**
2 * All Rights Reserved
3 *
4 * Copyright (c) 2025 taskylizard
5 *
6 * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7 */
8import type { IconifyJSON } from '@iconify-json/octicon'
9import type { MarkdownRenderer } from 'vitepress'
10import { iconTooltips } from './tooltip'
11
12// Icons that need to be used should be imported here
13import { icons as akar } from '@iconify-json/akar-icons'
14import { icons as ic } from '@iconify-json/ic'
15import { icons as iconoir } from '@iconify-json/iconoir'
16import { icons as logos } from '@iconify-json/logos'
17import { icons as lucide } from '@iconify-json/lucide'
18import { icons as materials } from '@iconify-json/material-symbols'
19import { icons as mdi } from '@iconify-json/mdi'
20import { icons as mingcute } from '@iconify-json/mingcute'
21import { icons as octicon } from '@iconify-json/octicon'
22import { icons as ri } from '@iconify-json/ri'
23import { icons as simple } from '@iconify-json/simple-icons'
24import { icons as twemoji } from '@iconify-json/twemoji'
25import { icons as uil } from '@iconify-json/uil'
26
27// 1. Install emoji pack with `pnpm add -D @iconify-json/<icon>`
28// 2. Import them like I did above
29// 3. Add it to this emojis array, like I did for octicon, and add a prefix
30const emojis: { pack: IconifyJSON; prefix?: string }[] = [
31 // Default emojis (twemoji)
32 { pack: twemoji },
33 // octicon emojis, prefixed with "octicon-"
34 { pack: octicon, prefix: 'octicon-' },
35 { pack: logos, prefix: 'logos-' },
36 { pack: ic, prefix: 'ic-' },
37 { pack: mingcute, prefix: 'mingcute-' },
38 { pack: mdi, prefix: 'mdi-' },
39 { pack: materials, prefix: 'material-symbols-' },
40 { pack: simple, prefix: 'simple-icons-' },
41 { pack: lucide, prefix: 'lucide-' },
42 { pack: uil, prefix: 'uil-' },
43 { pack: ri, prefix: 'ri-' },
44 { pack: akar, prefix: 'akar-icons-' },
45 { pack: iconoir, prefix: 'iconoir-' }
46]
47
48// Add aliases here: [icon, label?]
49// Label is optional — omit for icons that don't need a tooltip.
50const aliasDefs: Record<string, [string, string?]> = {
51
52 // Operating System
53 and: ['simple-icons-android', 'Android'],
54 ios: ['simple-icons-apple', 'iOS / iPadOS'],
55 win: ['simple-icons-windows', 'Windows'],
56 app: ['ri-finder-fill', 'MacOS'],
57 lin: ['simple-icons-linux', 'Linux'],
58 bsd: ['simple-icons-freebsd', 'BSD'],
59 cmd: ['material-symbols-terminal-rounded', 'CLI / TUI'],
60
61 // Browser
62 ff: ['simple-icons-firefoxbrowser', 'Firefox / Firefox based'],
63 cr: ['simple-icons-googlechrome', 'Chrome / Chromium based'],
64 web: ['mdi-web', 'Website / Web-based'],
65
66 // program
67 py: ['simple-icons-python', 'Python'],
68 npm: ['mdi-npm-variant', 'npm'],
69 js: ['simple-icons-javascript', 'JavaScript'],
70 css: ['mdi-language-css3', 'CSS'],
71 dock: ['simple-icons-docker', 'Docker'],
72
73 // Source code
74 src: ['mdi-package-variant', 'Source Code'],
75 cs: ['mdi-package-variant-closed-remove', 'Closed Source'],
76
77 // Network Type
78 ddl: ['material-symbols-cloud-download-outline-rounded', 'Direct / HTTP(S) Download'],
79 mag: ['lucide-magnet', 'Torrent / Magnet Download'],
80 usnt: ['material-symbols-newspaper-rounded', 'Usenet / NZB download'],
81
82
83 // Manga & Anime
84 sync: ['material-symbols-sync', 'Built-in sync system w/ Tracker(s)'],
85 msync: ['material-symbols-rule-settings-rounded', 'Sync using MAL-Sync'],
86 ie: ['mingcute-transfer-2-fill', 'Import / Export'],
87 cmnt: ['ic-round-mode-comment', 'Comment section'],
88 frm: ['ic-round-forum', 'Forum'],
89
90 cc: ['mdi-closed-caption', 'Soft Subtitle / CC'],
91 hs: ['mdi-hulu', 'Hardsubs'],
92 sup: ['mingcute-server-fill', 'Self-uploaded (Own storage or video host)'],
93 scrpr: ['mingcute-shovel-fill', 'Scraper (Pulling from other host sites)'],
94
95 up: ['material-symbols-upload', 'User / scanlator upload'],
96 ms: ['material-symbols-file-copy-rounded', 'Multiple chapter sources'],
97 ps: ['material-symbols-file-copy-outline-rounded', 'Unlabeled / Poorly labeled / Partial multi-source'],
98 ss: ['material-symbols-file-copy-off-rounded', 'Single source'],
99 sp: ['lucide-file', 'Single Page Mode'],
100 dp: ['lucide-book-open', 'Dual Page Mode'],
101 ls: ['lucide-scroll', 'Long-Strip Mode'],
102 lsg: ['ri-page-separator', 'Long-Strip with gaps'],
103
104 // Tracking
105 mal: ['simple-icons-myanimelist', 'MyAnimeList'],
106 al: ['simple-icons-anilist', 'AniList'],
107 k: ['simple-icons-kitsu', 'Kitsu'],
108 shiki: ['simple-icons-shikimori','Shikimori'],
109 simkl: ['simple-icons-simkl', 'Simkl'],
110 tmdb: ['simple-icons-themoviedatabase', 'TMDB'],
111 lstfm: ['simple-icons-lastdotfm', 'Lastfm'],
112 igdb: ['simple-icons-igdb', 'IGDB'],
113
114 // Social
115 d: ['simple-icons-discord', 'Discord'],
116 f: ['simple-icons-4chan', '4chan'],
117 x: ['simple-icons-twitter', 'Twitter'],
118 tg: ['simple-icons-telegram', 'Telegram'],
119 vk: ['simple-icons-vk', 'VK'],
120
121 // Other Websites
122 steam: ['simple-icons-steam', 'Steam'],
123 gog: ['mdi-gog', 'GOG'],
124 iarch: ['simple-icons-internetarchive', 'Internet Archive'],
125 apple: ['simple-icons-apple','Apple product'],
126 wikip: ['simple-icons-wikipedia','WikiPedia'],
127
128 // Price
129 paid: ['ic-round-attach-money', 'Paid'],
130 fm: ['ic-round-add-shopping-cart', 'Freemium'],
131 free: ['ic-round-money-off-csred', 'Has free content'],
132 sub: ['ic-round-currency-exchange', 'Subscription'],
133 coin: ['akar-icons-coin', 'Coin / Point'],
134
135 // Region
136 global: ['twemoji-globe-showing-asia-australia', 'Global'],
137
138 ljp: ['twemoji-flag-japan', 'Japanese'],
139 lkr: ['twemoji-flag-south-korea', 'Korean'],
140 lcn: ['twemoji-flag-china', 'Chinese'],
141 ltw: ['twemoji-flag-taiwan', 'Taiwanese'],
142 lge: ['twemoji-flag-germany', 'German'],
143 len: ['twemoji-flag-united-kingdom', 'English'],
144 lru: ['twemoji-flag-russia', 'Russian'],
145 lgr: ['twemoji-flag-greece', 'Greek'],
146 lpo: ['twemoji-flag-poland', 'Polish'],
147 lsp: ['twemoji-flag-spain', 'Spanish'],
148 lbr: ['twemoji-flag-brazil', 'Brazilian'],
149
150 ccn: ['twemoji-flag-china', 'China'],
151 cuk: ['twemoji-flag-united-kingdom', 'United Kingdom'],
152 cge: ['twemoji-flag-germany', 'Germany'],
153 cus: ['twemoji-flag-united-states', 'United States'],
154 ccy: ['twemoji-flag-cyprus', 'Cyprus'],
155 cca: ['twemoji-flag-canada', 'Canada'],
156 cswi: ['twemoji-flag-switzerland', 'Switzerland'],
157 cswe: ['twemoji-flag-sweden', 'Sweden'],
158 cit: ['twemoji-flag-italy', 'Italy'],
159 cgib: ['twemoji-flag-gibraltar', 'Gibraltar'],
160 cukr: ['twemoji-flag-ukraine', 'Ukraine'],
161 cindo: ['twemoji-flag-indonesia', 'Indonesia'],
162 cindi: ['twemoji-flag-india', 'India'],
163 ctur: ['twemoji-flag-turkiye', 'Turkey'],
164 cban: ['twemoji-flag-bangladesh', 'Bangladesh'],
165 cfr: ['twemoji-flag-france', 'France'],
166 cvie: ['twemoji-flag-vietnam', 'Vietnam'],
167 cbr: ['twemoji-flag-brazil', 'Brazil'],
168
169
170 // Storage
171 sgd: ['simple-icons-googledrive', 'Google Drive'],
172 sm: ['simple-icons-mega', 'MEGA'],
173 smf: ['simple-icons-mediafire', 'MediaFire'],
174 host: ['mdi-snail', 'Rate-limited / Paywalled Host'],
175
176
177 // General
178 s: ['twemoji-glowing-star', 'Favorite'],
179 e: ['mdi-puzzle', 'Extension'],
180 n: ['material-symbols-science', 'Nightly build'],
181 tv: ['material-symbols-tv-gen-outline-rounded', 'Supports TV layout'],
182 alt: ['ic-round-looks-two', 'Alternative'],
183 ero: ['twemoji-no-one-under-eighteen', 'R18'],
184 acc: ['material-symbols-person-add', 'Needs account'],
185 rss: ['simple-icons-rss', 'RSS Feed'],
186 prx: ['material-symbols-directions-alt', 'Proxies / Mirrors'],
187 tf: ['mdi-airplane', 'Testflight'],
188 more: ['mdi-arrow-right-bold', 'Related'],
189 prev: ['material-symbols-arrow-forward-ios-rounded','Related to Prior URL'],
190 help: ['material-symbols-help', 'Help / Docs'],
191 ded: ['twemoji-headstone','Inactive / Retired'],
192 strm: ['material-symbols-play-circle-outline', 'Stream'],
193 lcl: ['iconoir-floppy-disk', 'Local file'],
194 batch: ['material-symbols-package-2-outline', 'Batch Download'],
195 yes: ['twemoji-check-mark-button', 'Yes / Available'],
196 no: ['twemoji-cross-mark', 'No / Unavailable']
197}
198
199// Derived maps from aliasDefs
200const aliases: Record<string, string> = {}
201const aliasLabels: Record<string, string> = {}
202for (const [key, [icon, label]] of Object.entries(aliasDefs)) {
203 aliases[key] = icon
204 if (label) aliasLabels[key] = label
205}
206
207// Custom icons using UnoCSS inline collection
208const customIconAliases: Record<string, string> = {
209 'custom-circle': 'inline-circle'
210 // Add more custom icon aliases here
211}
212
213const defs: Record<string, string> = {}
214
215// Add pack icons to defs
216for (const elem of emojis) {
217 for (const key in elem.pack.icons) {
218 if (elem.prefix) defs[elem.prefix + key] = ''
219 else defs[key] = ''
220 }
221}
222
223// Add custom icon aliases to defs
224for (const [alias, _] of Object.entries(customIconAliases)) {
225 defs[alias] = ''
226}
227
228for (const [alias, fullName] of Object.entries(aliases)) {
229 defs[alias] = defs[fullName] !== undefined ? '' : 'INVALID_ALIAS'
230}
231
232export { aliases, defs }
233
234export function emojiRender(md: MarkdownRenderer) {
235 md.renderer.rules.emoji = (tokens, idx) => {
236 const markup = tokens[idx].markup
237 const label = aliasLabels[markup] || iconTooltips[markup]
238
239 const tip = label?.replace(/"/g, '"')
240 const wrap = (cls: string) => tip
241 ? `<span class="icon-tip" data-tip="${tip}" tabindex="-1"><span class="${cls}"></span></span>`
242 : `<span class="${cls}"></span>`
243
244 // Check for custom icon aliases first
245 if (customIconAliases[markup]) return wrap(`i-${customIconAliases[markup]}`)
246
247 // Check for aliases
248 if (aliases[markup]) return wrap(`i-${aliases[markup]}`)
249
250 // Check for prefixed icons
251 for (const emoji of emojis) {
252 if (markup.startsWith(emoji.prefix!)) return wrap(`i-${markup}`)
253 }
254
255 // Default to twemoji
256 return wrap(`i-twemoji-${markup}`)
257 }
258}
259
260export function movePlugin(
261 plugins: { name: string }[],
262 pluginAName: string,
263 order: 'before' | 'after',
264 pluginBName: string
265) {
266 const pluginBIndex = plugins.findIndex((p) => p.name === pluginBName)
267 if (pluginBIndex === -1) return
268
269 const pluginAIndex = plugins.findIndex((p) => p.name === pluginAName)
270 if (pluginAIndex === -1) return
271
272 if (order === 'before' && pluginAIndex > pluginBIndex) {
273 const pluginA = plugins.splice(pluginAIndex, 1)[0]
274 plugins.splice(pluginBIndex, 0, pluginA)
275 }
276
277 if (order === 'after' && pluginAIndex < pluginBIndex) {
278 const pluginA = plugins.splice(pluginAIndex, 1)[0]
279 plugins.splice(pluginBIndex, 0, pluginA)
280 }
281}