docs/.vitepress/configs/markdown/emoji.ts
293 lines · 11212 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: ['material-symbols-terminal-rounded', '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
106 up: ['material-symbols-upload', 'User / scanlator upload'],
107 ms: ['material-symbols-file-copy-rounded', 'Multiple chapter sources'],
108 ps: ['material-symbols-file-copy-outline-rounded', 'Unlabeled / Poorly labeled / Partial multi-source'],
109 ss: ['material-symbols-file-copy-off-rounded', 'Single source'],
110 sp: ['lucide-file', 'Single Page Mode'],
111 dp: ['lucide-book-open', 'Dual Page Mode'],
112 ls: ['lucide-scroll', 'Long-Strip Mode'],
113 lsg: ['material-symbols-page-footer-sharp', 'Long-Strip with gaps'],
114
115 // Tracking
116 mal: ['simple-icons-myanimelist', 'MyAnimeList'],
117 al: ['simple-icons-anilist', 'AniList'],
118 k: ['simple-icons-kitsu', 'Kitsu'],
119 shiki: ['simple-icons-shikimori','Shikimori'],
120 simkl: ['simple-icons-simkl', 'Simkl'],
121 tmdb: ['simple-icons-themoviedatabase', 'TMDB'],
122 lstfm: ['simple-icons-lastdotfm', 'Lastfm'],
123 igdb: ['simple-icons-igdb', 'IGDB'],
124
125 // Social
126 d: ['simple-icons-discord', 'Discord'],
127 f: ['simple-icons-4chan', '4chan'],
128 x: ['simple-icons-twitter', 'Twitter'],
129 tg: ['simple-icons-telegram', 'Telegram'],
130 vk: ['simple-icons-vk', 'VK'],
131
132 // Other Websites
133 steam: ['simple-icons-steam', 'Steam'],
134 gog: ['mdi-gog', 'GOG'],
135 iarch: ['simple-icons-internetarchive', 'Internet Archive'],
136 apple: ['simple-icons-apple','Apple product'],
137 wikip: ['simple-icons-wikipedia','WikiPedia'],
138
139 // Price
140 paid: ['streamline-ultimate-cash-payment-bills-bold', "Good ol' money"],
141 fm: ['ic-round-add-shopping-cart', 'Freemium'],
142 free: ['streamline-sharp-tag-free-circle-remix', 'Has free/demo content'],
143 sub: ['ic-round-currency-exchange', 'Subscription'],
144 coin: ['akar-icons-coin', 'Coin / Point'],
145
146 // Region
147 global: ['twemoji-globe-showing-asia-australia', 'Global'],
148
149 ljp: ['twemoji-flag-japan', 'Japanese'],
150 lkr: ['twemoji-flag-south-korea', 'Korean'],
151 lcn: ['twemoji-flag-china', 'Chinese'],
152 ltw: ['twemoji-flag-taiwan', 'Taiwanese'],
153 lfr: ['twemoji-flag-france', 'French'],
154 lge: ['twemoji-flag-germany', 'German'],
155 len: ['twemoji-flag-united-kingdom', 'English'],
156 lru: ['twemoji-flag-russia', 'Russian'],
157 lgr: ['twemoji-flag-greece', 'Greek'],
158 lpo: ['twemoji-flag-poland', 'Polish'],
159 lsp: ['twemoji-flag-spain', 'Spanish'],
160 lbr: ['twemoji-flag-brazil', 'Brazilian'],
161
162 ccn: ['twemoji-flag-china', 'China'],
163 cuk: ['twemoji-flag-united-kingdom', 'United Kingdom'],
164 cge: ['twemoji-flag-germany', 'Germany'],
165 cus: ['twemoji-flag-united-states', 'United States'],
166 ccy: ['twemoji-flag-cyprus', 'Cyprus'],
167 cca: ['twemoji-flag-canada', 'Canada'],
168 cswi: ['twemoji-flag-switzerland', 'Switzerland'],
169 cswe: ['twemoji-flag-sweden', 'Sweden'],
170 cit: ['twemoji-flag-italy', 'Italy'],
171 cgib: ['twemoji-flag-gibraltar', 'Gibraltar'],
172 cukr: ['twemoji-flag-ukraine', 'Ukraine'],
173 cindo: ['twemoji-flag-indonesia', 'Indonesia'],
174 cindi: ['twemoji-flag-india', 'India'],
175 ctur: ['twemoji-flag-turkiye', 'Turkey'],
176 cban: ['twemoji-flag-bangladesh', 'Bangladesh'],
177 cfr: ['twemoji-flag-france', 'France'],
178 cvie: ['twemoji-flag-vietnam', 'Vietnam'],
179 cbr: ['twemoji-flag-brazil', 'Brazil'],
180
181
182 // Storage
183 sgd: ['simple-icons-googledrive', 'Google Drive'],
184 sm: ['simple-icons-mega', 'MEGA'],
185 smf: ['simple-icons-mediafire', 'MediaFire'],
186 host: ['mdi-snail', 'Rate-limited / Paywalled Host'],
187
188
189 // General
190 s: ['twemoji-glowing-star', 'Favorite'],
191 e: ['mdi-puzzle', 'Extension'],
192 n: ['material-symbols-science', 'Nightly build'],
193 tv: ['material-symbols-tv-gen-outline-rounded', 'Supports TV layout'],
194 alt: ['ic-round-looks-two', 'Alternative'],
195 ero: ['twemoji-no-one-under-eighteen', 'R18'],
196 acc: ['material-symbols-person-add', 'Needs account'],
197 rss: ['simple-icons-rss', 'RSS Feed'],
198 prx: ['material-symbols-directions-alt', 'Proxies / Mirrors'],
199 tf: ['mdi-airplane', 'Testflight'],
200 more: ['mdi-arrow-right-bold', 'Related'],
201 prev: ['mdi-arrow-right-thick','Related to Prior URL'],
202 help: ['material-symbols-help', 'Help / Docs'],
203 ded: ['twemoji-headstone','Inactive / Retired'],
204 strm: ['material-symbols-play-circle-outline', 'Stream'],
205 lcl: ['iconoir-floppy-disk', 'Local file'],
206 batch: ['material-symbols-package-2-outline', 'Batch Download'],
207 yes: ['twemoji-check-mark-button', 'Yes / Available'],
208 no: ['twemoji-cross-mark', 'No / Unavailable']
209}
210
211// Derived maps from aliasDefs
212const aliases: Record<string, string> = {}
213const aliasLabels: Record<string, string> = {}
214for (const [key, [icon, label]] of Object.entries(aliasDefs)) {
215 aliases[key] = icon
216 if (label) aliasLabels[key] = label
217}
218
219// Custom icons using UnoCSS inline collection
220const customIconAliases: Record<string, string> = {
221 'custom-circle': 'inline-circle'
222 // Add more custom icon aliases here
223}
224
225const defs: Record<string, string> = {}
226
227// Add pack icons to defs
228for (const elem of emojis) {
229 for (const key in elem.pack.icons) {
230 if (elem.prefix) defs[elem.prefix + key] = ''
231 else defs[key] = ''
232 }
233}
234
235// Add custom icon aliases to defs
236for (const [alias, _] of Object.entries(customIconAliases)) {
237 defs[alias] = ''
238}
239
240for (const [alias, fullName] of Object.entries(aliases)) {
241 defs[alias] = defs[fullName] !== undefined ? '' : 'INVALID_ALIAS'
242}
243
244export { aliases, defs }
245
246export function emojiRender(md: MarkdownRenderer) {
247 md.renderer.rules.emoji = (tokens, idx) => {
248 const markup = tokens[idx].markup
249 const label = aliasLabels[markup] || iconTooltips[markup]
250
251 const tip = label?.replace(/"/g, '"')
252 const wrap = (cls: string) => tip
253 ? `<span class="icon-tip" data-tip="${tip}" tabindex="-1"><span class="${cls}"></span></span>`
254 : `<span class="${cls}"></span>`
255
256 // Check for custom icon aliases first
257 if (customIconAliases[markup]) return wrap(`i-${customIconAliases[markup]}`)
258
259 // Check for aliases
260 if (aliases[markup]) return wrap(`i-${aliases[markup]}`)
261
262 // Check for prefixed icons
263 for (const emoji of emojis) {
264 if (markup.startsWith(emoji.prefix!)) return wrap(`i-${markup}`)
265 }
266
267 // Default to twemoji
268 return wrap(`i-twemoji-${markup}`)
269 }
270}
271
272export function movePlugin(
273 plugins: { name: string }[],
274 pluginAName: string,
275 order: 'before' | 'after',
276 pluginBName: string
277) {
278 const pluginBIndex = plugins.findIndex((p) => p.name === pluginBName)
279 if (pluginBIndex === -1) return
280
281 const pluginAIndex = plugins.findIndex((p) => p.name === pluginAName)
282 if (pluginAIndex === -1) return
283
284 if (order === 'before' && pluginAIndex > pluginBIndex) {
285 const pluginA = plugins.splice(pluginAIndex, 1)[0]
286 plugins.splice(pluginBIndex, 0, pluginA)
287 }
288
289 if (order === 'after' && pluginAIndex < pluginBIndex) {
290 const pluginA = plugins.splice(pluginAIndex, 1)[0]
291 plugins.splice(pluginBIndex, 0, pluginA)
292 }
293}