Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/layouts/GlobalLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const { title, description, focus, image } = Astro.props;
---

<html lang="ja" class="bg-gray-50 text-gray-800" data-theme="light">
<Meta {title} {description} image={image} />
<head>
<Meta {title} {description} image={image} />
</head>
<body class="min-h-full w-full">
<ClientRouter />
<Header {focus} />
Expand Down
7 changes: 6 additions & 1 deletion src/layouts/meta.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
import { addOrigin } from "+/lib/utils";

interface Props {
title: string | null;
description: string | null;
Expand All @@ -22,7 +24,10 @@ const url = Astro.url.href;
<meta property="og:site_name" content="ut.code();" />
<meta property="og:title" content={title} />
{description && <meta property="og:description" content={description} />}
<meta property="og:image" content={image?.src ?? "/utcode-logo/normal.png"} />
<meta
property="og:image"
content={addOrigin(image?.src ?? "/utcode-logo/normal.png", Astro.site)}
/>
<meta property="og:url" content={url} />
<meta property="og:locale" content="ja_JP" />
<meta name="twitter:card" content="summary_large_image" />
Expand Down
11 changes: 11 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -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;
}