mirror of
https://github.com/dergigi/boris.git
synced 2026-02-10 17:44:34 +01:00
feat: add bookmark filter buttons by content type
- Add BookmarkFilters component with icon-based filter buttons - Create bookmarkTypeClassifier utility for content type classification - Filter bookmarks by article, video, note, or web types - Apply filters across all bookmark lists (private, public, web, sets) - Style filter buttons to match existing UI design
This commit is contained in:
41
src/utils/bookmarkTypeClassifier.ts
Normal file
41
src/utils/bookmarkTypeClassifier.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { IndividualBookmark } from '../types/bookmarks'
|
||||
import { extractUrlsFromContent } from '../services/bookmarkHelpers'
|
||||
import { classifyUrl } from './helpers'
|
||||
|
||||
export type BookmarkType = 'article' | 'video' | 'note' | 'web'
|
||||
|
||||
/**
|
||||
* Classifies a bookmark into one of the content types
|
||||
*/
|
||||
export function classifyBookmarkType(bookmark: IndividualBookmark): BookmarkType {
|
||||
if (bookmark.kind === 30023) return 'article'
|
||||
|
||||
const isWebBookmark = bookmark.kind === 39701
|
||||
const webBookmarkUrl = isWebBookmark ? bookmark.tags.find(t => t[0] === 'd')?.[1] : null
|
||||
|
||||
const extractedUrls = webBookmarkUrl
|
||||
? [webBookmarkUrl.startsWith('http') ? webBookmarkUrl : `https://${webBookmarkUrl}`]
|
||||
: extractUrlsFromContent(bookmark.content)
|
||||
|
||||
const firstUrl = extractedUrls[0]
|
||||
if (!firstUrl) return 'note'
|
||||
|
||||
const urlType = classifyUrl(firstUrl)?.type
|
||||
|
||||
if (urlType === 'youtube' || urlType === 'video') return 'video'
|
||||
if (urlType === 'article') return 'article'
|
||||
|
||||
return 'web'
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters bookmarks by type
|
||||
*/
|
||||
export function filterBookmarksByType(
|
||||
bookmarks: IndividualBookmark[],
|
||||
filterType: 'all' | BookmarkType
|
||||
): IndividualBookmark[] {
|
||||
if (filterType === 'all') return bookmarks
|
||||
return bookmarks.filter(bookmark => classifyBookmarkType(bookmark) === filterType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user