From 25e699c090005ffe53d2ea0a24f6d680b1f2277e Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:52:03 +0900 Subject: [PATCH] fix og image --- bun.lock | 2 +- src/layouts/GlobalLayout.astro | 4 +++- src/layouts/meta.astro | 7 ++++++- src/lib/utils.ts | 11 +++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/lib/utils.ts diff --git a/bun.lock b/bun.lock index 45c8529b..fe012c16 100644 --- a/bun.lock +++ b/bun.lock @@ -18,7 +18,7 @@ "date-fns": "^4.1.0", "markdown-to-txt": "^2.0.1", "sharp": "^0.34.1", - "svelte": "^5.26.1", + "svelte": "^5.26.2", }, "devDependencies": { "@astrojs/check": "^0.9.4", diff --git a/src/layouts/GlobalLayout.astro b/src/layouts/GlobalLayout.astro index d92f9e48..ebdd7c17 100644 --- a/src/layouts/GlobalLayout.astro +++ b/src/layouts/GlobalLayout.astro @@ -18,7 +18,9 @@ const { title, description, focus, image } = Astro.props; --- - + + +
diff --git a/src/layouts/meta.astro b/src/layouts/meta.astro index 8d990d0b..433751da 100644 --- a/src/layouts/meta.astro +++ b/src/layouts/meta.astro @@ -1,4 +1,6 @@ --- +import { addOrigin } from "+/lib/utils"; + interface Props { title: string | null; description: string | null; @@ -22,7 +24,10 @@ const url = Astro.url.href; {description && } - + diff --git a/src/lib/utils.ts b/src/lib/utils.ts new file mode 100644 index 00000000..6224a8f6 --- /dev/null +++ b/src/lib/utils.ts @@ -0,0 +1,11 @@ +export function addOrigin(url: string, site: URL | undefined) { + if (url.startsWith("http://") || url.startsWith("https://")) { + return url; + } + if (url.startsWith("/")) { + if (!site) throw new Error("site is undefined"); + return site.origin + url; + } + console.warn("WARNING: unknown URL schema:", url); + return url; +}