import { t } from '../../utils/intl' import { createMemo, For, Show } from 'solid-js' import type { Shout } from '../../graphql/types.gen' import { capitalize } from '../../utils' import { translit } from '../../utils/ru2en' import { Icon } from '../_shared/Icon' import styles from './Card.module.scss' import { locale } from '../../stores/ui' import { clsx } from 'clsx' import { CardTopic } from './CardTopic' import { RatingControl } from '../Article/RatingControl' import { SharePopup } from '../Article/SharePopup' import stylesHeader from '../Nav/Header.module.scss' interface ArticleCardProps { settings?: { noicon?: boolean noimage?: boolean nosubtitle?: boolean noauthor?: boolean nodate?: boolean isGroup?: boolean photoBottom?: boolean additionalClass?: string isFeedMode?: boolean isFloorImportant?: boolean isWithCover?: boolean isBigTitle?: boolean isVertical?: boolean isShort?: boolean withBorder?: boolean isCompact?: boolean isSingle?: boolean isBeside?: boolean } article: Shout } const getTitleAndSubtitle = (article: Shout): { title: string; subtitle: string } => { let title = article.title let subtitle = article.subtitle if (!subtitle) { let tt = article.title?.split('. ') || [] if (tt?.length === 1) { tt = article.title?.split(/{!|\?|:|;}\s/) || [] } if (tt && tt.length > 1) { const sep = article.title?.replace(tt[0], '').split(' ', 1)[0] title = tt[0] + (sep === '.' || sep === ':' ? '' : sep) subtitle = capitalize(article.title?.replace(tt[0] + sep, ''), true) } } return { title, subtitle } } export const ArticleCard = (props: ArticleCardProps) => { const mainTopic = props.article.topics.find((articleTopic) => articleTopic.slug === props.article.mainTopic) || props.article.topics[0] const formattedDate = createMemo(() => { return new Date(props.article.createdAt) .toLocaleDateString(locale(), { month: 'long', day: 'numeric', year: 'numeric' }) .replace(' г.', '') }) const { title, subtitle } = getTitleAndSubtitle(props.article) const { cover, layout, slug, authors, stat } = props.article return (
{title
{(author, index) => { let name = author.name if (locale() !== 'ru') { name = name === 'Дискурс' ? 'Discours' : translit(name) } return ( <> 0}>, {name} ) }}
{formattedDate()}
} />
) }