Next.js(App Router)でヘッドレスCMS【④<body>解読】
app/layout.tsxを見てみる
生成元のコードです。<body>タグがあります。
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import Head from "next/head";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}
生成された<body>要素を見てみた
生成されたHTMLはこちら。
<body class="__variable_4d318d __variable_ea5f4b antialiased">...</body>
設定少ないですね。
ChatGPTに聞いてみた
body関連のコードを抜粋し、「これはどういうことですか?」と聞いてみました。
このコードは、
<body>
タグに2つの異なるフォント(Geist Sans
とGeist Mono
)を設定し、それに加えてテキストを滑らかに表示するためのantialiased
クラスも適用しています。
まとめ
bodyタグでは単純に、フォント関連の設定(フォント種類とアンチエイリアス)をしていました。