From d49476236ef5ead335fec4aee38e14ca9b5dbf8d Mon Sep 17 00:00:00 2001 From: GauthierWebDev Date: Sun, 20 Apr 2025 13:22:58 +0200 Subject: [PATCH] feat: Add buildPublicUrl function and use it in config page image URL --- app/buildPublicUrl.ts | 11 +++++++++++ app/pages/+config.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 app/buildPublicUrl.ts diff --git a/app/buildPublicUrl.ts b/app/buildPublicUrl.ts new file mode 100644 index 0000000..405d105 --- /dev/null +++ b/app/buildPublicUrl.ts @@ -0,0 +1,11 @@ +import { config } from "@/config"; + +export function buildPublicUrl(resource: string) { + const { BASE_URL } = config; + + if (BASE_URL) { + return new URL(resource, BASE_URL).toString(); + } + + return resource; +} diff --git a/app/pages/+config.ts b/app/pages/+config.ts index 3645a51..6ebd06f 100755 --- a/app/pages/+config.ts +++ b/app/pages/+config.ts @@ -1,5 +1,6 @@ import type { Config } from "vike/types"; +import { buildPublicUrl } from "@/buildPublicUrl"; import Layout from "@/layouts/LayoutDefault"; import vikeSolid from "vike-solid/config"; @@ -25,7 +26,7 @@ export default { class: "flex min-h-full bg-white", }, - image: "/opengraph/og.png", + image: buildPublicUrl("/opengraph/og.png"), prerender: true, prefetchStaticAssets: "hover",