UNPKG

@tycoonsystems/tycoon-modules

Version:
1 lines 5.39 kB
function _extends(){return(_extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var a,n=arguments[e];for(a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t}).apply(this,arguments)}import React from"react";import{HMSDurationToSeconds}from"@tycoonsystems/tycoon-modules/utility/utility/date";const constructGeneral=(t,e)=>{const a=[];if(e&&t)if(e.siteTitle&&a.push({type:"meta",property:"og:site_name",content:""+e.siteTitle}),e?.profileData&&"/p"===t?.pathname){var n=e.profileData;if(a.push({type:"meta",property:"og:type",content:"profile"}),n?.user){const p=n.user;[["profile:first_name","firstName"],["profile:last_name","lastName"]].map(t=>{p?.meta&&p?.meta[t[1]]&&a.push({type:"meta",property:t[0],content:""+p.meta[t[1]],path:"p"})}),p?.username&&a.push({type:"meta",property:"profile:username",content:""+p.username,path:"p"})}}else{var r;e?.articleData&&"/a"===t?.pathname?(n=e?.articleData,e.articleData?.authorData&&(r=(r=n.authorData)?.meta?.firstName?`${r.meta.firstName}${r.meta?.lastName?" "+r.meta.lastName:""} @`+(r?.username??""):r?.username??"")&&a.push({type:"meta",name:"author",content:r}),a.push({type:"title",innerHTML:n.title}),a.push({type:"meta",name:"description",content:n.description}),a.push({type:"meta",name:"keywords",content:n?.tags?.join?n.tags.join():""}),a.push({type:"link",ref:"canonical",href:"https://"+e.domainUrl+t.asPath}),a.push({type:"meta",property:"og:title",content:n.title}),a.push({type:"meta",property:"og:description",content:n.description}),a.push({type:"meta",property:"og:type",content:"article"}),a.push({type:"meta",property:"og:url",content:"https://"+e.domainUrl+t.asPath}),a.push({type:"meta",property:"og:image",content:""+(n?.images&&n.images[0]?n.images[0]:"")}),a.push({type:"meta",name:"twitter:card",content:"summary_large_image"}),a.push({type:"meta",name:"twitter:title",content:n.title}),a.push({type:"meta",name:"twitter:description",content:n.description}),a.push({type:"meta",name:"twitter:image",content:""+(n.images&&n.images[0]?n.images[0]:"")})):e?.watchData&&"/w"===t?.pathname&&(r=e?.watchData,e.watchData?.authorData&&(n=(n=r.authorData)?.meta?.firstName?`${n.meta.firstName}${n.meta?.lastName?" "+n.meta.lastName:""} @`+(n?.username??""):n?.username??"")&&a.push({type:"meta",name:"author",content:n}),a.push({type:"title",innerHTML:r.title}),a.push({type:"meta",name:"description",content:r?.description??""}),a.push({type:"meta",name:"keywords",content:r?.tags?.join?r.tags.join():""}),a.push({type:"link",ref:"canonical",href:"https://"+e.domainUrl+t.asPath}),a.push({type:"meta",property:"og:title",content:r.title}),a.push({type:"meta",property:"og:description",content:r.description}),a.push({type:"meta",property:"og:type",content:"video.other"}),a.push({type:"meta",property:"og:url",content:"https://"+e.domainUrl+t.asPath}),a.push({type:"meta",property:"og:image",content:r?.thumbtrack&&r.thumbtrack[0]&&e?.cdn?.static?e.cdn.static+"/thumbtrack/"+r.thumbtrack[0]:""}),a.push({type:"meta",property:"og:video:type",content:"video/mp4"}),a.push({type:"meta",property:"og:video:width",content:""+(r?.meta?.resolution?.w??"")}),a.push({type:"meta",property:"og:video:height",content:""+(r?.meta?.resolution?.h??"")}),(n=HMSDurationToSeconds(r?.duration??"")??0)&&a.push({type:"meta",property:"og:video:duration",content:n}),a.push({type:"meta",name:"twitter:card",content:"player"}),a.push({type:"meta",name:"twitter:title",content:r.title}),a.push({type:"meta",name:"twitter:description",content:r.description}),a.push({type:"meta",name:"twitter:image",content:r?.thumbtrack&&r.thumbtrack[0]&&e?.cdn?.static?e.cdn.static+"/thumbtrack/"+r.thumbtrack[0]:""}),a.push({type:"meta",name:"twitter:player:width",content:""+(r?.meta?.resolution?.w??"")}),a.push({type:"meta",name:"twitter:player:height",content:""+(r?.meta?.resolution?.h??"")}),a.push({type:"meta",name:"twitter:player:stream:content_type",content:"video/mp4"}),n=n?`PT${Math.floor(n/3600)}H${Math.floor(n%3600/60)}M${Math.ceil(n%60)}S`:"",n={type:"ldSchema","@context":"https://schema.org","@type":"VideoObject",name:""+r.title,description:""+r.description,thumbnailUrl:r?.thumbtrack&&r.thumbtrack[0]&&e?.cdn?.static?e.cdn.static+"/thumbtrack/"+r.thumbtrack[0]:"",uploadDate:""+(r?.publish&&!isNaN(Number(r.publish))?new Date(Number(r.publish)).toISOString():""),duration:n,contentUrl:"https://"+e.domainUrl+t.asPath,embedUrl:"https://"+e.domainUrl+t.asPath,potentialAction:{"@type":"WatchAction",target:"https://"+e.domainUrl+t.asPath},publisher:{"@type":"Organization",name:""+(r?.production??"")},hasPart:r?.timeline?.map?r.timeline.filter(t=>"clip"===t?.type).map(t=>{var e={"@type":"Clip",name:""+t.name,startOffset:""+t.startOffset,url:""+t.url};return t.endOffset&&(e.endOffset=""+t.endOffset),e}):[]},a.push(n))}return a},paintMeta=t=>t.map((t,e)=>{var a=t.type;const n={};Object.entries(t).map(t=>{t&&t[0]&&"type"!==t[0]&&Object.prototype.hasOwnProperty.call(t,1)&&(n[t[0]]=t[1])});t=structuredClone(n);let r;n.innerHTML&&(r=n.innerHTML,delete t.innerHTML);try{return"ldSchema"===a?React.createElement("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(n)}}):null!==r?React.createElement(a,_extends({key:e},t),r):React.createElement(a,_extends({key:e},t))}catch(t){return React.createElement("meta",{key:e})}});export{constructGeneral,paintMeta};