fix(stats): serve stats og image from banner
This commit is contained in:
+1
-1
@@ -165,7 +165,7 @@ export const app = new sst.cloudflare.x.SolidStart("Stats", {
|
|||||||
domain: `stats.${domain}`,
|
domain: `stats.${domain}`,
|
||||||
link: [database, EMAILOCTOPUS_API_KEY],
|
link: [database, EMAILOCTOPUS_API_KEY],
|
||||||
environment: {
|
environment: {
|
||||||
PUBLIC_URL: `https://stats.${domain}/stats`,
|
PUBLIC_URL: `https://${domain}/stats`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export async function statsProxy(evt: APIEvent) {
|
|||||||
targetUrl.hostname = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
|
targetUrl.hostname = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
|
||||||
targetUrl.port = ""
|
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)
|
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 |
@@ -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 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 ibmPlexMonoBoldLatin1 from "@ibm/plex/IBM-Plex-Mono/fonts/split/woff2/IBMPlexMono-Bold-Latin1.woff2?url"
|
||||||
import opencodeWordmarkDark from "../asset/logo-ornate-dark.svg"
|
import opencodeWordmarkDark from "../asset/logo-ornate-dark.svg"
|
||||||
import statsUnfurlRankings from "../asset/unfurl-rankings.png?url"
|
|
||||||
import {
|
import {
|
||||||
getStatsHomeData,
|
getStatsHomeData,
|
||||||
type CacheRatioEntry,
|
type CacheRatioEntry,
|
||||||
@@ -42,7 +41,8 @@ const rangeLabels: Record<UsageRange, string> = {
|
|||||||
}
|
}
|
||||||
const statsHomeTitle = "OpenCode Stats"
|
const statsHomeTitle = "OpenCode Stats"
|
||||||
const statsHomeDescription = "OpenCode usage, market share, token cost, and session cost 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 statsUnfurlAlt = "OpenCode Stats wordmark on a dark patterned background"
|
||||||
const headerLinks = [
|
const headerLinks = [
|
||||||
{ href: "#top-models", label: "Top Models" },
|
{ href: "#top-models", label: "Top Models" },
|
||||||
@@ -147,11 +147,11 @@ const getGitHubStars = query(async () => {
|
|||||||
export default function StatsHome() {
|
export default function StatsHome() {
|
||||||
const event = getRequestEvent()
|
const event = getRequestEvent()
|
||||||
event?.response.headers.set("Cache-Control", "public, max-age=60, s-maxage=300, stale-while-revalidate=86400")
|
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,
|
import.meta.env.BASE_URL,
|
||||||
event?.request.url ?? (typeof window === "undefined" ? statsHomeFallbackUrl : window.location.href),
|
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 data = createAsync(() => getData())
|
||||||
const githubStars = createAsync(() => getGitHubStars())
|
const githubStars = createAsync(() => getGitHubStars())
|
||||||
const [themePreference, setThemePreference] = createSignal<ThemePreference>("system")
|
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 {
|
function isThemePreference(value: string | null): value is ThemePreference {
|
||||||
return value === "dark" || value === "light" || value === "system"
|
return value === "dark" || value === "light" || value === "system"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user