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

2da3ce29bcdcda3282e74c823c5c346c9faa0614
wotaku/docs/.vitepress/configs/markdown/emoji.ts
Duck Update emoji.tsd814304a7d 6 months ago

295 lines · 11278 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  cswi: ['twemoji-flag-switzerland', 'Switzerland'],
172  cswe: ['twemoji-flag-sweden', 'Sweden'],
173  cit: ['twemoji-flag-italy', 'Italy'],
174  cgib: ['twemoji-flag-gibraltar', 'Gibraltar'],
175  cukr: ['twemoji-flag-ukraine', 'Ukraine'],
176  cindo: ['twemoji-flag-indonesia', 'Indonesia'],
177  cindi: ['twemoji-flag-india', 'India'],
178  ctur: ['twemoji-flag-turkiye', 'Turkey'],
179  cban: ['twemoji-flag-bangladesh', 'Bangladesh'],
180  cfr: ['twemoji-flag-france', 'France'],
181  cvie: ['twemoji-flag-vietnam', 'Vietnam'],
182  cbr: ['twemoji-flag-brazil', 'Brazil'],
183
184
185  // Storage
186  sgd: ['simple-icons-googledrive', 'Google Drive'],
187  sm: ['simple-icons-mega', 'MEGA'],
188  smf: ['simple-icons-mediafire', 'MediaFire'],
189  host: ['mdi-snail', 'Rate-limited / Paywalled Host'],
190
191  
192  // General
193  s: ['twemoji-glowing-star', 'Favorite'],
194  e: ['mdi-puzzle', 'Extension'],
195  n: ['material-symbols-science', 'Nightly build'],
196  alt: ['ic-round-looks-two', 'Alternative'],
197  ero: ['twemoji-no-one-under-eighteen', 'R18'],
198  acc: ['material-symbols-person-add', 'Needs account'],
199  rss: ['simple-icons-rss', 'RSS Feed'],
200  prx: ['material-symbols-directions-alt', 'Proxies / Mirrors'],
201  tf: ['mdi-airplane', 'Testflight'],
202  more: ['mdi-arrow-right-bold', 'Related'],
203  prev: ['mdi-arrow-right-thick','Related to Prior URL'],
204  help: ['material-symbols-help', 'Help / Docs'],
205  ded: ['twemoji-headstone','Inactive / Retired'],
206  strm: ['material-symbols-play-circle-outline', 'Stream'],
207  lcl: ['iconoir-floppy-disk', 'Local file'],
208  batch: ['material-symbols-package-2-outline', 'Batch Download'],
209  yes: ['lucide-check', 'Yes / Available'],
210  no: ['lucide-x', 'No / Unavailable']
211}
212
213// Derived maps from aliasDefs
214const aliases: Record<string, string> = {}
215const aliasLabels: Record<string, string> = {}
216for (const [key, [icon, label]] of Object.entries(aliasDefs)) {
217  aliases[key] = icon
218  if (label) aliasLabels[key] = label
219}
220
221// Custom icons using UnoCSS inline collection
222const customIconAliases: Record<string, string> = {
223  'custom-circle': 'inline-circle'
224  // Add more custom icon aliases here
225}
226
227const defs: Record<string, string> = {}
228
229// Add pack icons to defs
230for (const elem of emojis) {
231  for (const key in elem.pack.icons) {
232    if (elem.prefix) defs[elem.prefix + key] = ''
233    else defs[key] = ''
234  }
235}
236
237// Add custom icon aliases to defs
238for (const [alias, _] of Object.entries(customIconAliases)) {
239  defs[alias] = ''
240}
241
242for (const [alias, fullName] of Object.entries(aliases)) {
243  defs[alias] = defs[fullName] !== undefined ? '' : 'INVALID_ALIAS'
244}
245
246export { aliases, defs }
247
248export function emojiRender(md: MarkdownRenderer) {
249  md.renderer.rules.emoji = (tokens, idx) => {
250    const markup = tokens[idx].markup
251    const label = aliasLabels[markup] || iconTooltips[markup]
252
253    const tip = label?.replace(/"/g, '&quot;')
254    const wrap = (cls: string) => tip
255      ? `<span class="icon-tip" data-tip="${tip}" tabindex="-1"><span class="${cls}"></span></span>`
256      : `<span class="${cls}"></span>`
257
258    // Check for custom icon aliases first
259    if (customIconAliases[markup]) return wrap(`i-${customIconAliases[markup]}`)
260
261    // Check for aliases
262    if (aliases[markup]) return wrap(`i-${aliases[markup]}`)
263
264    // Check for prefixed icons
265    for (const emoji of emojis) {
266      if (markup.startsWith(emoji.prefix!)) return wrap(`i-${markup}`)
267    }
268
269    // Default to twemoji
270    return wrap(`i-twemoji-${markup}`)
271  }
272}
273
274export function movePlugin(
275  plugins: { name: string }[],
276  pluginAName: string,
277  order: 'before' | 'after',
278  pluginBName: string
279) {
280  const pluginBIndex = plugins.findIndex((p) => p.name === pluginBName)
281  if (pluginBIndex === -1) return
282
283  const pluginAIndex = plugins.findIndex((p) => p.name === pluginAName)
284  if (pluginAIndex === -1) return
285
286  if (order === 'before' && pluginAIndex > pluginBIndex) {
287    const pluginA = plugins.splice(pluginAIndex, 1)[0]
288    plugins.splice(pluginBIndex, 0, pluginA)
289  }
290
291  if (order === 'after' && pluginAIndex < pluginBIndex) {
292    const pluginA = plugins.splice(pluginAIndex, 1)[0]
293    plugins.splice(pluginBIndex, 0, pluginA)
294  }
295}
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