import React from 'react'; import { Link } from 'gatsby'; import { GatsbyImage } from 'gatsby-plugin-image'; import SkeletonLoader from 'tiny-skeleton-loader-react'; import { ImageObject } from '../../types'; import { Theme, useGlobalState } from '../../context'; import * as classes from './style.module.css'; export interface ArticleCard { image?: ImageObject; category: string; title: string; publishedAt: Date; readingTime?: string; link: string; } interface ArticleCardProps { data: ArticleCard; showBanner?: boolean; } export function ArticleCard(props: ArticleCardProps): React.ReactElement { const { globalState } = useGlobalState(); const darkModeEnabled = globalState.theme === Theme.Dark; // Needed to differentiate between external and internal links (whether or not we use Gatsby Link) const absoluteUrl = props.data.link.indexOf('://') > 0 || props.data.link.indexOf('//') === 0; const articleCard = (
{props.showBanner && (
{props.data.image && props.data.image.src && ( )}
)}
{props.data.category}

{props.data.title}

{formatDate(props.data.publishedAt)} {props.data.readingTime && {props.data.readingTime}}
); return absoluteUrl ? ( {articleCard} ) : ( {articleCard} ); } export function ArticleCardSkeleton(): React.ReactElement { const { globalState } = useGlobalState(); const darkModeEnabled = globalState.theme === Theme.Dark; return (
); } function formatDate(date: Date): string { const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; return `${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`; }