Code for my personal website
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 54 lines 1.5 kB view raw
1import { clsx } from 'clsx'; 2import { twMerge } from 'tailwind-merge'; 3import type { 4 CombineClassName, 5 DateRange, 6 FormatDate, 7 ReadingTime 8} from './types'; 9 10const combineClassNames: CombineClassName = (...inputs) => { 11 return twMerge(clsx(inputs)); 12}; 13 14const formatDate: FormatDate = (date) => { 15 return Intl.DateTimeFormat('en-US', { 16 month: 'short', 17 day: '2-digit', 18 year: 'numeric' 19 }).format(date); 20}; 21 22const readingTime: ReadingTime = (html) => { 23 const textOnly = html.replace(/<[^>]+>/g, ''); 24 const wordCount = textOnly.split(/\s+/).length; 25 const readingTimeMinutes = (wordCount / 200 + 1).toFixed(); 26 return `${readingTimeMinutes} min read`; 27}; 28 29const dateRange: DateRange = (startDate, endDate) => { 30 const startDateObj = new Date(startDate); 31 const endDateObj = endDate ? new Date(endDate) : null; 32 33 const startMonth = startDateObj.toLocaleString('default', { month: 'short' }); 34 const startYear = startDateObj.getFullYear().toString(); 35 let endMonth; 36 let endYear; 37 38 if (endDateObj) { 39 if (typeof endDateObj === 'string') { 40 endMonth = ''; 41 endYear = endDateObj; 42 } else { 43 endMonth = endDateObj.toLocaleString('default', { month: 'short' }); 44 endYear = endDateObj.getFullYear().toString(); 45 } 46 } else { 47 endMonth = 'Present'; 48 endYear = ''; 49 } 50 51 return `${startMonth} ${startYear} - ${endMonth} ${endYear}`; 52}; 53 54export { combineClassNames, formatDate, readingTime, dateRange };