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

575696a14f8e51bc61744aaa4db1b7e9b4e38ad6
wotaku/docs/.vitepress/configs/markdown/emoji.ts
Duck Steam and GOG575696a14f 7 months ago

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