Files
boris/src/utils/helpers.ts
Gigi d6756dc5a1 refactor: remove duplicate formatDate function from helpers.ts
- Keep single formatDate implementation in bookmarkUtils.tsx
- Both BookmarkList and BookmarkItem already import from bookmarkUtils
- Maintain DRY principle by eliminating duplication
2025-10-03 09:27:56 +02:00

40 lines
1.2 KiB
TypeScript

// Extract pubkeys from nprofile strings in content
export const extractNprofilePubkeys = (content: string): string[] => {
const nprofileRegex = /nprofile1[a-z0-9]+/gi
const matches = content.match(nprofileRegex) || []
const unique = new Set<string>(matches)
return Array.from(unique)
}
export type UrlType = 'video' | 'image' | 'youtube' | 'article'
export interface UrlClassification {
type: UrlType
buttonText: string
}
export const classifyUrl = (url: string): UrlClassification => {
const urlLower = url.toLowerCase()
// Check for YouTube
if (urlLower.includes('youtube.com') || urlLower.includes('youtu.be')) {
return { type: 'youtube', buttonText: 'WATCH NOW' }
}
// Check for video extensions
const videoExtensions = ['.mp4', '.webm', '.ogg', '.mov', '.avi', '.mkv', '.m4v']
if (videoExtensions.some(ext => urlLower.includes(ext))) {
return { type: 'video', buttonText: 'WATCH NOW' }
}
// Check for image extensions
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg', '.bmp', '.ico']
if (imageExtensions.some(ext => urlLower.includes(ext))) {
return { type: 'image', buttonText: 'VIEW NOW' }
}
// Default to article
return { type: 'article', buttonText: 'READ NOW' }
}