Head.astro 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ---
  2. import { Base64 } from "js-base64";
  3. import type { Props } from '@astrojs/starlight/props'
  4. import Default from '@astrojs/starlight/components/Head.astro'
  5. import config from '../../config.mjs'
  6. const slug = Astro.url.pathname.replace(/^\//, "").replace(/\/$/, "");
  7. const {
  8. entry: {
  9. data: { title , description },
  10. },
  11. } = Astro.locals.starlightRoute;
  12. const isDocs = slug.startsWith("docs")
  13. let encodedTitle = '';
  14. let ogImage = `${config.url}/social-share.png`;
  15. let truncatedDesc = '';
  16. if (isDocs) {
  17. // Truncate to fit S3's max key size
  18. encodedTitle = encodeURIComponent(
  19. Base64.encode(
  20. // Convert to ASCII
  21. encodeURIComponent(
  22. // Truncate to fit S3's max key size
  23. title.substring(0, 700)
  24. )
  25. )
  26. );
  27. if (description) {
  28. truncatedDesc = encodeURIComponent(description.substring(0, 400))
  29. }
  30. ogImage = `${config.socialCard}/opencode-docs/${encodedTitle}.png?desc=${truncatedDesc}`;
  31. }
  32. ---
  33. { slug === "" && (
  34. <title>{title} | AI coding agent built for the terminal</title>
  35. )}
  36. <Default {...Astro.props}><slot /></Default>
  37. { (isDocs || !slug.startsWith("s")) && (
  38. <meta property="og:image" content={ogImage} />
  39. <meta property="twitter:image" content={ogImage} />
  40. )}