agora-ai/backend/src/services/nameGenerator.js
Muyue 97c4ad9f6c Add marked syntax highlighting and random name generator
- Install marked and highlight.js for better markdown rendering
- Create nameGenerator service with 50 unique names
- Update DocumentViewer to use marked instead of regex parsing
- Add syntax highlighting for code blocks
- Improve styling for code with proper colors
2025-10-18 22:57:59 +02:00

38 lines
992 B
JavaScript

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const namesPath = path.join(__dirname, '../../data/names.txt')
let allNames = []
function loadNames() {
try {
const content = fs.readFileSync(namesPath, 'utf-8')
allNames = content
.split('\n')
.map(name => name.trim())
.filter(name => name.length > 0)
} catch (error) {
console.error('Error loading names:', error)
allNames = ['Alex', 'Jordan', 'Casey', 'Morgan', 'Riley'] // Fallback
}
}
// Load names on module import
loadNames()
export function getRandomNames(count) {
if (count > allNames.length) {
throw new Error(`Cannot get ${count} unique names. Only ${allNames.length} available.`)
}
const shuffled = [...allNames].sort(() => Math.random() - 0.5)
return shuffled.slice(0, count)
}
export function getRandomName() {
return allNames[Math.floor(Math.random() * allNames.length)]
}