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

dc37a0812a9971107e75ecfdb141c3d5bf0289fc
wotaku/docs/.vitepress/theme/components/extrepo/helpers.ts
Duck sora redo8f36a0b628 4 months ago

39 lines · 1288 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 escapeHtml(text: string): string {
26  return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
27}
28
29export function ratingIcon(rating: Rating): string {
30  return rating === 'nsfw' ? 'i-twemoji-no-one-under-eighteen' : 'i-twemoji-warning'
31}
32
33export function ratingTitle(rating: Rating): string {
34  return rating === 'nsfw' ? 'NSFW' : 'Mature'
35}
36
37export function contentTypeLabel(type: string): string {
38  return type.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ')
39}
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