fix(stats): serve stats og image from banner

This commit is contained in:
Adam 2026-06-03 10:53:07 -05:00
parent f4851e3bd9
commit d08fedaccc
No known key found for this signature in database
GPG Key ID: 9CB48779AF150E75
5 changed files with 14 additions and 7 deletions

View File

@ -165,7 +165,7 @@ export const app = new sst.cloudflare.x.SolidStart("Stats", {
domain: `stats.${domain}`,
link: [database, EMAILOCTOPUS_API_KEY],
environment: {
PUBLIC_URL: `https://stats.${domain}/stats`,
PUBLIC_URL: `https://${domain}/stats`,
},
})

View File

@ -8,7 +8,7 @@ export async function statsProxy(evt: APIEvent) {
targetUrl.hostname = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
targetUrl.port = ""
if (targetUrl.pathname.startsWith("/stats/_build/")) {
if (targetUrl.pathname.startsWith("/stats/_build/") || targetUrl.pathname === "/stats/banner.png") {
targetUrl.pathname = targetUrl.pathname.slice("/stats".length)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@ -11,7 +11,6 @@ import ibmPlexMonoMediumLatin1 from "@ibm/plex/IBM-Plex-Mono/fonts/split/woff2/I
import ibmPlexMonoSemiBoldLatin1 from "@ibm/plex/IBM-Plex-Mono/fonts/split/woff2/IBMPlexMono-SemiBold-Latin1.woff2?url"
import ibmPlexMonoBoldLatin1 from "@ibm/plex/IBM-Plex-Mono/fonts/split/woff2/IBMPlexMono-Bold-Latin1.woff2?url"
import opencodeWordmarkDark from "../asset/logo-ornate-dark.svg"
import statsUnfurlRankings from "../asset/unfurl-rankings.png?url"
import {
getStatsHomeData,
type CacheRatioEntry,
@ -42,7 +41,8 @@ const rangeLabels: Record<UsageRange, string> = {
}
const statsHomeTitle = "OpenCode Stats"
const statsHomeDescription = "OpenCode usage, market share, token cost, and session cost stats."
const statsHomeFallbackUrl = "https://stats.opencode.ai"
const statsHomeFallbackUrl = "https://opencode.ai/stats/"
const statsUnfurlPath = "banner.png"
const statsUnfurlAlt = "OpenCode Stats wordmark on a dark patterned background"
const headerLinks = [
{ href: "#top-models", label: "Top Models" },
@ -147,11 +147,11 @@ const getGitHubStars = query(async () => {
export default function StatsHome() {
const event = getRequestEvent()
event?.response.headers.set("Cache-Control", "public, max-age=60, s-maxage=300, stale-while-revalidate=86400")
const statsHomeUrl = new URL(
const statsHomeUrl = getStatsHomeUrl(
import.meta.env.BASE_URL,
event?.request.url ?? (typeof window === "undefined" ? statsHomeFallbackUrl : window.location.href),
).toString()
const statsUnfurlUrl = new URL(statsUnfurlRankings, statsHomeUrl).toString()
)
const statsUnfurlUrl = new URL(statsUnfurlPath, statsHomeUrl).toString()
const data = createAsync(() => getData())
const githubStars = createAsync(() => getGitHubStars())
const [themePreference, setThemePreference] = createSignal<ThemePreference>("system")
@ -217,6 +217,13 @@ export default function StatsHome() {
)
}
function getStatsHomeUrl(base: string, requestUrl: string) {
const url = new URL(base, requestUrl)
if (url.hostname === "stats.opencode.ai") return "https://opencode.ai/stats/"
if (url.hostname === "stats.dev.opencode.ai") return "https://dev.opencode.ai/stats/"
return url.toString()
}
function isThemePreference(value: string | null): value is ThemePreference {
return value === "dark" || value === "light" || value === "system"
}