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

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

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