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

d4975cb59765c778e9a00df2fd5e4d8412eb0e8b
wotaku/docs/.vitepress/configs/markdown/emoji.ts
Memenami erdr icon fix5a9651d991 7 months ago

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