import { UserPlusIcon, UsersThreeIcon } from '@phosphor-icons/react' import { format } from 'date-fns' import { BookOpenText, Clock3, Hash } from 'lucide-react' import React from 'react' import ReactMarkdown from 'react-markdown' import { isDark } from '../../../../utils/theme' import { DefaultLayout } from '../../../components/DefaultLayout' import { QRCodeWithAvatar } from '../../../components/QRCodeWithAvatar' import type { PosterProps } from '../../../types/ctx' import { DouyinCommentIcon, DouyinFavoriteIcon, DouyinLikeIcon, DouyinShareIcon } from '../../components/Icons' import type { DouyinArticleWorkData } from './types' const getTitleClassName = (titleLength: number): string => { if (titleLength > 96) return 'text-[42px] leading-[1.34]' if (titleLength > 72) return 'text-[48px] leading-[1.3]' if (titleLength > 48) return 'text-[54px] leading-[1.26]' return 'text-[62px] leading-[1.18]' } const getArticleImageUrl = (image?: DouyinArticleWorkData['images'][number]): string | undefined => image?.ai_high_image_url || image?.high_image_url || image?.origin_image_url || image?.markdown_url const preprocessMarkdown = (markdown: string): string => markdown.replace(/!\[([^\]]*)\]\(([^\s)]+)(?:\s+width=\d+)?(?:\s+height=\d+)?\)/g, '![$1]($2)') const DouyinDiffuseBackground: React.FC> = ({ data }) => { const coverUrl = getArticleImageUrl(data.images[0]) return (
{coverUrl && ( )}
) } const DouyinPosterHeader: React.FC> = ({ data, ctx }) => { const { avater_url, username, create_time, read_time } = data return (
头像
{username}
{create_time} 阅读 {read_time} 分钟
抖音
) } const DouyinArticleTitle: React.FC> = ({ data }) => (

{data.title}

) const DouyinArticleContent: React.FC> = ({ data }) => { const imageMap = new Map() data.images.forEach((image) => { const highQualityUrl = getArticleImageUrl(image) if (highQualityUrl) imageMap.set(image.markdown_url, highQualityUrl) }) return (

{children}

, h2: ({ children }) =>

{children}

, h3: ({ children }) =>

{children}

, h4: ({ children }) =>

{children}

, p: ({ children }) =>

{children}

, ul: ({ children }) => (
    {children}
), ol: ({ children }) => (
    {children}
), li: ({ children }) =>
  • {children}
  • , strong: ({ children }) => {children}, em: ({ children }) => {children}, blockquote: ({ children }) => (
    {children}
    ), code: ({ children }) => {children}, img: ({ src, alt }) => { const imageUrl = src ? imageMap.get(src) || src : '' if (!imageUrl) return null return (
    {alt {alt && alt !== '图片描述' && (
    {alt}
    )}
    ) } }} > {preprocessMarkdown(data.markdown)}
    ) } const DouyinSignalLine: React.FC> = ({ data }) => { const { dianzan, pinglun, shouchang, share } = data const renderTime = format(new Date(), 'yyyy-MM-dd HH:mm:ss') const stats = [ { icon: DouyinLikeIcon, value: dianzan, label: '点赞' }, { icon: DouyinCommentIcon, value: pinglun, label: '评论' }, { icon: DouyinFavoriteIcon, value: shouchang, label: '收藏' }, { icon: DouyinShareIcon, value: share, label: '分享' } ] return (
    {stats.map((stat) => { const Icon = stat.icon return (
    {stat.label}
    {stat.value}
    ) })}
    图片生成于: {renderTime}
    ) } const DouyinPosterFooter: React.FC> = ({ data, ctx }) => { const { avater_url, username, 抖音号, 获赞, 关注, 粉丝, share_url } = data const stats = [ { icon: DouyinLikeIcon, iconSize: 26, label: '获赞', value: 获赞 }, { icon: UserPlusIcon, iconSize: 32, label: '关注', value: 关注 }, { icon: UsersThreeIcon, iconSize: 32, label: '粉丝', value: 粉丝 } ] return (
    头像
    {username}
    抖音号: {抖音号}
    {stats.map((stat) => { const Icon = stat.icon return (
    {stat.label}
    {stat.value}
    ) })}
    扫码查看作品详情
    ) } export const DouyinArticleWork: React.FC> = React.memo((props) => (
    )) DouyinArticleWork.displayName = 'DouyinArticleWork' export default DouyinArticleWork