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