My personal site hosted @ https://indexx.dev
1--- 2type StatusRes = { 3 text: string, 4 createdAt: string, 5 link: string 6} 7 8const url = new URL("/api/status", Astro.request.url); 9const data = await fetch(url); 10const { text, createdAt, link } = await data.json() as StatusRes; 11 12function getRelativeTime(dateStr: string) { 13 const date = new Date(dateStr); 14 const now = new Date(); 15 const diff = now.getTime() - date.getTime(); 16 17 const minutes = Math.floor(diff / 60000); 18 const hours = Math.floor(minutes / 60); 19 const days = Math.floor(hours / 24); 20 21 if (days > 0) return `${days} days ago`; 22 if (hours > 0) return `${hours} hours ago`; 23 if (minutes > 0) return `${minutes} minutes ago`; 24 return 'just now'; 25} 26 27const timeAgo = getRelativeTime(createdAt); 28 29const date = new Date(createdAt); 30const now = new Date(); 31const diff = now.getTime() - date.getTime(); 32const days = Math.floor(diff / (1000 * 60 * 60 * 24)); 33 34const oldStatusClasses = days > 3 ? 'opacity-75 text-decoration-line-through' : ''; 35--- 36 37<a href={link} target="_blank" class={`badge bg-white ${oldStatusClasses}`}>Index is.. "{text}", {timeAgo}</a>