import React from 'react' import {Inline, Stack, Text, useTheme} from '@sanity/ui' import Feedback from './Feedback' const MAX_CHARACTERS = 145 function splitUrl(url: string) { if (!url) return [] const urlObj = new URL(url) const urlParts = [urlObj.origin] if (urlObj.pathname) { urlParts.push(...urlObj.pathname.split(`/`).filter(Boolean)) } // Remove last part if it's long-ish // This is my guess as to what Google does if (urlParts[urlParts.length - 1].length > 30) { urlParts.pop() } return urlParts } type SERPPreviewProps = { metaDescription: string title: string url: string } export default function SERPPreview({title, metaDescription, url}: SERPPreviewProps) { const isDarkMode = useTheme().sanity.color.dark return ( {url ? ( {splitUrl(url).map((part, index) => ( {index === 0 ? part : `› ${part}`} ))} ) : ( URL not found, your frontend may be missing a canonical tag )} {title ? ( {title} ) : null} {metaDescription ? ( {metaDescription.length > MAX_CHARACTERS ? `${metaDescription.slice(0, MAX_CHARACTERS)}...` : metaDescription} ) : null} ) }