import React from 'react' import { GoogleDriveBlock } from 'notion-types' import { formatDistance } from 'date-fns' import { useNotionContext } from '../context' import { cs } from '../utils' import { GracefulImage } from './graceful-image' export const GoogleDrive: React.FC<{ block: GoogleDriveBlock className?: string }> = ({ block, className }) => { const { components, mapImageUrl } = useNotionContext() const properties = block.format?.drive_properties if (!properties) return null let domain try { const url = new URL(properties.url) domain = url.hostname } catch (err) { // ignore invalid urls for robustness } return (
{properties.title && (
{properties.title}
)} {properties.modified_time && (
Last modified{' '} {properties.user_name ? `by ${properties.user_name} ` : ''} {formatDistance( new Date(properties.modified_time), new Date() )}{' '} ago
)} {properties.icon && domain && (
{properties.icon && (
)} {domain && (
{domain}
)}
)}
) }