Skip to content

Commit 349babf

Browse files
committed
seo: add og:type
1 parent f656dce commit 349babf

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

src/layouts/GlobalLayout.astro

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "+/global.css";
44
import { ClientRouter } from "astro:transitions";
55
import Footer from "+/components/Footer.astro";
66
import Header from "+/components/Header.astro";
7+
import type { OgType } from "+/lib/types";
78
import type { Focus } from "+/schema";
89
import Meta from "./meta.astro";
910
@@ -13,13 +14,19 @@ interface Props {
1314
focus: Focus;
1415
class?: string;
1516
image: ImageMetadata | null;
17+
type?: OgType;
1618
}
17-
const { title, description, focus, image } = Astro.props;
19+
const { title, description, focus, image, type } = Astro.props;
1820
---
1921

20-
<html lang="ja" class="bg-gray-50 text-gray-800" data-theme="light">
22+
<html
23+
lang="ja"
24+
prefix="og: http://ogp.me/ns#"
25+
class="bg-gray-50 text-gray-800"
26+
data-theme="light"
27+
>
2128
<head>
22-
<Meta {title} {description} image={image} />
29+
<Meta {title} {description} image={image} og_type={type} />
2330
</head>
2431
<body class="min-h-[100vh]">
2532
<ClientRouter />

src/layouts/meta.astro

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
---
2-
import { addOrigin } from "+/lib/utils";
2+
import type { OgType } from "+/lib/types.ts";
3+
import { addOrigin } from "+/lib/utils.ts";
34
45
interface Props {
56
title: string | null;
67
description: string | null;
78
keywords?: string[];
89
image: ImageMetadata | null;
10+
og_type?: OgType | undefined;
911
}
10-
const { title, description, keywords = [], image } = Astro.props;
12+
const { title, description, keywords = [], image, og_type } = Astro.props;
1113
const url = Astro.url.href;
1214
---
1315

@@ -21,6 +23,7 @@ const url = Astro.url.href;
2123
name="description"
2224
content={description ?? "東京大学のソフトウェアエンジニアリングコミュニティ"}
2325
/>
26+
<meta property="og:type" content={og_type ?? "website"} />
2427
<meta property="og:site_name" content="ut.code();" />
2528
<meta property="og:title" content={title} />
2629
{description && <meta property="og:description" content={description} />}

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type OgType = "website" | "profile" | "article";

src/pages/articles/[...id].astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const author = article.data.author && (await getMember(article.data.author.id));
2525
description={null}
2626
focus={Focus.articles}
2727
image={article.data.image}
28+
type="article"
2829
>
2930
<div class="mt-2 text-center lg:px-8">
3031
<Picture

src/pages/members/[member].astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const articles = await getArticles({
2929
description={`ut.code(); のメンバーの${member.data.nameJa}です。`}
3030
focus={Focus.members}
3131
image={member.data.upperBodyImage}
32+
type="profile"
3233
>
3334
<main class="w-full">
3435
<div

0 commit comments

Comments
 (0)