your personal website on atproto - mirror blento.app
at fix-cached-posts 62 lines 2.0 kB view raw
1import type { CardDefinition } from '../../types'; 2import { listRecords } from '$lib/atproto'; 3import MarginCard from './MarginCard.svelte'; 4import MarginCardSettings from './MarginCardSettings.svelte'; 5 6export type MarginEntry = { 7 type: 'bookmark' | 'annotation' | 'highlight'; 8 uri: string; 9 value: any; 10 createdAt: string; 11}; 12 13export const MarginCardDefinition = { 14 type: 'margin', 15 contentComponent: MarginCard, 16 settingsComponent: MarginCardSettings, 17 createNew: (card) => { 18 card.w = 4; 19 card.mobileW = 8; 20 card.h = 4; 21 card.mobileH = 6; 22 }, 23 loadData: async (_items, { did }) => { 24 const [bookmarks, annotations, highlights] = await Promise.all([ 25 listRecords({ did, collection: 'at.margin.bookmark' }).catch(() => []), 26 listRecords({ did, collection: 'at.margin.annotation' }).catch(() => []), 27 listRecords({ did, collection: 'at.margin.highlight' }).catch(() => []) 28 ]); 29 30 const entries: MarginEntry[] = [ 31 ...bookmarks.map((r: any) => ({ 32 type: 'bookmark' as const, 33 uri: r.uri, 34 value: r.value, 35 createdAt: r.value.createdAt 36 })), 37 ...annotations.map((r: any) => ({ 38 type: 'annotation' as const, 39 uri: r.uri, 40 value: r.value, 41 createdAt: r.value.createdAt 42 })), 43 ...highlights.map((r: any) => ({ 44 type: 'highlight' as const, 45 uri: r.uri, 46 value: r.value, 47 createdAt: r.value.createdAt 48 })) 49 ]; 50 51 entries.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()); 52 53 return entries; 54 }, 55 minH: 2, 56 canHaveLabel: true, 57 58 keywords: ['margin', 'bookmarks', 'annotations', 'highlights', 'reading', 'web'], 59 groups: ['Social'], 60 name: 'Margin highlights, bookmarks, annotations', 61 icon: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-4"><path stroke-linecap="round" stroke-linejoin="round" d="M17.593 3.322c1.1.128 1.907 1.077 1.907 2.185V21L12 17.25 4.5 21V5.507c0-1.108.806-2.057 1.907-2.185a48.507 48.507 0 0 1 11.186 0Z" /></svg>` 62} as CardDefinition & { type: 'margin' };