Head.astro 1.2 KB

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