summaryrefslogtreecommitdiffhomepage
path: root/packages/web/src/components/Head.astro
blob: 36f11c955ae49eecd7624b2d9b5f2304ee2b8a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
import { Base64 } from "js-base64";
import type { Props } from '@astrojs/starlight/props'
import Default from '@astrojs/starlight/components/Head.astro'
import config from '../../config.mjs'

const slug = Astro.url.pathname.replace(/^\//, "").replace(/\/$/, "");
const {
  entry: {
    data: { title },
  },
} = Astro.locals.starlightRoute;
const isDocs = slug.startsWith("docs")

let encodedTitle = '';
let ogImage = `${config.url}/social-share.png`;

if (isDocs) {
  // Truncate to fit S3's max key size
  encodedTitle = encodeURIComponent(
    Base64.encode(
      // Convert to ASCII
      encodeURIComponent(
        // Truncate to fit S3's max key size
        title.substring(0, 700)
      )
    )
  );
  ogImage = `${config.socialCard}/opencode-docs/${encodedTitle}.png`;
}
---

<Default {...Astro.props}><slot /></Default>

{ (isDocs || !slug.startsWith("s")) && (
  <meta property="og:image" content={ogImage} />
  <meta property="twitter:image" content={ogImage} />
)}