---
import type { StarlightRouteData } from '@astrojs/starlight/route-data'
import Default from '@astrojs/starlight/components/Head.astro'
import PostHog from '@components/PostHog.astro'

const route = Astro.locals.starlightRoute as StarlightRouteData

const imagePath = '/docs/opengraph.png'
const docsOgPath =
  typeof route.id === 'string' && route.id.length > 0
    ? `/docs/opengraph/${route.id
        .split('/')
        .map(segment => encodeURIComponent(segment))
        .join('/')}`
    : null
const imageUrl = Astro.site
  ? docsOgPath
    ? new URL(docsOgPath, Astro.site).toString()
    : new URL(imagePath, Astro.site).toString()
  : (docsOgPath ?? imagePath)

const pageTitle =
  typeof route.entry?.data?.title === 'string' && route.entry.data.title.trim()
    ? route.entry.data.title.trim()
    : route.siteTitle
---

<Default />
<meta name="twitter:image" content={imageUrl} />
<meta name="image" property="og:image" content={imageUrl} />
<meta property="og:image:secure_url" content={imageUrl} />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="1248" />
<meta property="og:image:height" content="628" />
<meta property="og:image:alt" content={`${pageTitle} | Daytona`} />
<meta name="algolia-site-verification" content="2988B4D95ECF88B6" />
{import.meta.env.PROD && <PostHog />}
