import * as React from 'react' import { Block } from 'notion-types' import { useNotionContext } from '../context' import { cs, formatNotionDateTime } from '../utils' import SvgTypeGitHub from '../icons/type-github' // External Object Instance export const EOI: React.FC<{ block: Block inline?: boolean className?: string }> = ({ block, inline, className }) => { const { components } = useNotionContext() const { original_url, attributes, domain } = block?.format || {} if (!original_url || !attributes) { return null } const title = attributes.find((attr) => attr.id === 'title')?.values[0] let owner = attributes.find((attr) => attr.id === 'owner')?.values[0] const lastUpdatedAt = attributes.find((attr) => attr.id === 'updated_at') ?.values[0] const lastUpdated = lastUpdatedAt ? formatNotionDateTime(lastUpdatedAt) : null let externalImage: React.ReactNode switch (domain) { case 'github.com': externalImage = if (owner) { const parts = owner.split('/') owner = parts[parts.length - 1] } break default: if (process.env.NODE_ENV !== 'production') { console.log( `Unsupported external_object_instance domain "${domain}"`, JSON.stringify(block, null, 2) ) } return null } return ( {externalImage && ( {externalImage} )} {title} {(owner || lastUpdated) && ( {owner && {owner}} {owner && lastUpdated && • } {lastUpdated && Updated {lastUpdated}} )} ) }