import { useMetaData } from '@websolutespa/bom-mixer-hooks'; import { IMetaData, TwitterCardApp, TwitterCardPlayer, TwitterCardType } from '@websolutespa/bom-mixer-models'; import Head from 'next/head'; import React from 'react'; export function renderTwitterCard(data: TwitterCardType): React.ReactElement[] { const tags: React.ReactElement[] = []; // Basic Twitter Card tags tags.push(); if (data.site) { tags.push(); } if (data.siteId) { tags.push(); } if (data.creator) { tags.push(); } if (data.creatorId) { tags.push(); } if (data.title) { tags.push(); } if (data.description) { tags.push(); } if (data.image) { tags.push(); } if (data.imageAlt) { tags.push(); } // Card-specific tags switch (data.card) { case 'app': { const appData = data as TwitterCardApp; if (appData.appNameIphone) { tags.push(); } if (appData.appIdIphone) { tags.push(); } if (appData.appUrlIphone) { tags.push(); } if (appData.appNameIpad) { tags.push(); } if (appData.appIdIpad) { tags.push(); } if (appData.appUrlIpad) { tags.push(); } if (appData.appNameGoogleplay) { tags.push( ); } if (appData.appIdGoogleplay) { tags.push( ); } if (appData.appUrlGoogleplay) { tags.push( ); } if (appData.appCountry) { tags.push(); } break; } case 'player': { const playerData = data as TwitterCardPlayer; tags.push(); tags.push( ); tags.push( ); if (playerData.playerStream) { tags.push(); } break; } } return tags; } export function TwitterCard({ item }: { item?: (metaData: IMetaData) => TwitterCardType }) { const metaData = useMetaData(); const twitterCard = item ? item(metaData) : metaData.twitterCard; if (twitterCard) { return ( {renderTwitterCard(twitterCard)} ); } return <>; }