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

9c6588973e856dbc27ebb283f0d963c792faa8df
wotaku/docs/.vitepress/configs/markdown/emoji.ts
Duck update0c1dad3246 5 months ago

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