mirror of
https://github.com/dergigi/boris.git
synced 2025-12-27 19:44:40 +01:00
- Keep single formatDate implementation in bookmarkUtils.tsx - Both BookmarkList and BookmarkItem already import from bookmarkUtils - Maintain DRY principle by eliminating duplication
40 lines
1.2 KiB
TypeScript
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' }
|
|
}
|
|
|