docs/.vitepress/configs/markdown/emoji.ts

3f64b71094f27ebc4d707ae743f176291a90f178
wotaku/docs/.vitepress/configs/markdown/emoji.ts

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

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form