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

6c6b5e2b7fa2db872838af467c4ef42be25f1e9c
wotaku/docs/.vitepress/configs/markdown/emoji.ts
Duck Good ol' money0048825d9f 6 months ago

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