From 6a7983a4ea9cb4ed6ec93f99f742df5a384cf807 Mon Sep 17 00:00:00 2001 From: Jay V Date: Fri, 27 Jun 2025 20:03:17 -0400 Subject: [PATCH] docs: adding more share images --- packages/web/astro.config.mjs | 18 ++---------- packages/web/config.mjs | 2 ++ packages/web/src/components/Head.astro | 38 ++++++++++++++++++++++++++ packages/web/src/pages/s/[id].astro | 3 +- 4 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 packages/web/src/components/Head.astro diff --git a/packages/web/astro.config.mjs b/packages/web/astro.config.mjs index 9099c6df..2ba90fe8 100644 --- a/packages/web/astro.config.mjs +++ b/packages/web/astro.config.mjs @@ -8,12 +8,11 @@ import config from "./config.mjs" import { rehypeHeadingIds } from "@astrojs/markdown-remark" import rehypeAutolinkHeadings from "rehype-autolink-headings" -const url = "https://opencode.ai" const github = "https://github.com/sst/opencode" // https://astro.build/config export default defineConfig({ - site: url, + site: config.url, output: "server", adapter: cloudflare({ imageService: "passthrough", @@ -41,20 +40,6 @@ export default defineConfig({ href: "/favicon.svg", }, }, - { - tag: "meta", - attrs: { - property: "og:image", - content: `${url}/social-share.png`, - }, - }, - { - tag: "meta", - attrs: { - property: "twitter:image", - content: `${url}/social-share.png`, - }, - }, ], editLink: { baseUrl: `${github}/edit/master/www/`, @@ -80,6 +65,7 @@ export default defineConfig({ ], components: { Hero: "./src/components/Hero.astro", + Head: "./src/components/Head.astro", Header: "./src/components/Header.astro", }, plugins: [ diff --git a/packages/web/config.mjs b/packages/web/config.mjs index 5b81f502..b6ec26e3 100644 --- a/packages/web/config.mjs +++ b/packages/web/config.mjs @@ -1,4 +1,6 @@ export default { + url: "https://opencode.ai", + socialCard: "https://social-cards.sst.dev", github: "https://github.com/sst/opencode", headerLinks: [ { name: "Home", url: "/" }, diff --git a/packages/web/src/components/Head.astro b/packages/web/src/components/Head.astro new file mode 100644 index 00000000..36f11c95 --- /dev/null +++ b/packages/web/src/components/Head.astro @@ -0,0 +1,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`; +} +--- + + + +{ (isDocs || !slug.startsWith("s")) && ( + + +)} diff --git a/packages/web/src/pages/s/[id].astro b/packages/web/src/pages/s/[id].astro index 7e8c7238..a81d2e78 100644 --- a/packages/web/src/pages/s/[id].astro +++ b/packages/web/src/pages/s/[id].astro @@ -2,6 +2,7 @@ import { Base64 } from "js-base64"; import config from "virtual:starlight/user-config"; +import config from '../../../config.mjs' import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'; import Share from "../../components/Share.tsx"; @@ -38,7 +39,7 @@ const encodedTitle = encodeURIComponent( ) ); -const ogImage = `https://social-cards.sst.dev/opencode-share/${encodedTitle}.png?model=${Array.from(models).join(",")}&version=${version}&id=${id}`; +const ogImage = `${config.socialCard}/opencode-share/${encodedTitle}.png?model=${Array.from(models).join(",")}&version=${version}&id=${id}`; ---