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

59e2770299344d1d729dd168c1fc261319fe0313
wotaku/docs/.vitepress/configs/markdown/emoji.ts
Duck safarifc8d700ec6 5 months ago

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