/* eslint-disable jsx-a11y/alt-text */ 'use client' import { Link } from '@chakra-ui/next-js' import { Alert, AlertIcon, AlertTitle, Heading, Stack, Text, } from '@chakra-ui/react' import { MDXRemote, MDXRemoteSerializeResult } from 'next-mdx-remote' import { highlight } from 'sugar-high' import { Tweet } from './Tweet' import { Standard } from '@typebot.io/nextjs' import { EndCta } from '@/components/Homepage/EndCta' import { Table } from './Table' import Image from 'next/image' type Props = { metadata: { title: string publishedAt: string } mdxSource: MDXRemoteSerializeResult } export const Post = ({ metadata, mdxSource }: Props) => ( {metadata.title} {formatDate(metadata.publishedAt)} , h2: (props) => , h3: (props) => , h4: (props) => , h5: (props) => , h6: (props) => , code: ({ children, ...props }) => { const codeHTML = highlight(children?.toString() ?? '') return ( ) }, // eslint-disable-next-line @typescript-eslint/no-explicit-any link: (props: any) => , Image: (props) => ( ), Callout: ({ children, title, ...props }) => ( {title ? {title} : null} {children} ), Tweet, Typebot: (props) => ( ), Youtube: ({ id }: { id: string }) => (
), Loom: ({ id }: { id: string }) => (
), Cta: (props) => ( ), Table, }} />
) function formatDate(date: string) { const currentDate = new Date().getTime() if (!date.includes('T')) { date = `${date}T00:00:00` } const targetDate = new Date(date).getTime() const timeDifference = Math.abs(currentDate - targetDate) const daysAgo = Math.floor(timeDifference / (1000 * 60 * 60 * 24)) const fullDate = new Date(date).toLocaleString('en-us', { month: 'long', day: 'numeric', year: 'numeric', }) if (daysAgo < 1) { return 'Today' } else if (daysAgo < 7) { return `${fullDate} (${daysAgo}d ago)` } else if (daysAgo < 30) { const weeksAgo = Math.floor(daysAgo / 7) return `${fullDate} (${weeksAgo}w ago)` } else if (daysAgo < 365) { const monthsAgo = Math.floor(daysAgo / 30) return `${fullDate} (${monthsAgo}mo ago)` } else { const yearsAgo = Math.floor(daysAgo / 365) return `${fullDate} (${yearsAgo}y ago)` } }