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