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