docs/.vitepress/theme/components/extrepo/helpers.ts

a92c62778d79ea32c814bfce5540e823c2ad6de1
wotaku/docs/.vitepress/theme/components/extrepo/helpers.ts

35 lines · 1129 bytes

 1import { LANG_FLAG_FALLBACK, LANG_FLAG_ICONS } from '../../../configs/markdown/langFlags'
 2import type { Rating } from './types'
 3
 4export function langFlagClass(lang: string): string {
 5  const key = lang.toLowerCase()
 6  const icon = LANG_FLAG_ICONS[key] ?? LANG_FLAG_ICONS[key.split('-')[0]] ?? LANG_FLAG_FALLBACK
 7  return `i-twemoji-${icon}`
 8}
 9
10const langDisplayNames = new Intl.DisplayNames(['en'], { type: 'language' })
11
12export function langLabel(lang: string): string {
13  if (lang.toLowerCase() === 'all') return 'Multi-language'
14  try {
15    return langDisplayNames.of(lang) ?? lang
16  } catch {
17    return lang
18  }
19}
20
21export function stripHtml(html: string): string {
22  return html.replace(/<[^>]*>/g, '').trim()
23}
24
25export function ratingIcon(rating: Rating): string {
26  return rating === 'nsfw' ? 'i-twemoji-no-one-under-eighteen' : 'i-twemoji-warning'
27}
28
29export function ratingTitle(rating: Rating): string {
30  return rating === 'nsfw' ? 'NSFW' : 'Mature'
31}
32
33export function contentTypeLabel(type: string): string {
34  return type.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ')
35}
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