refactor(fonts): move font definitions to a dedicated fonts module
This commit is contained in:
+1
-45
@@ -1,54 +1,10 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import localFont from "next/font/local";
|
||||
import { SessionProvider } from "@/providers/session-provider";
|
||||
import { geistSans, geistMono, athelas } from "@/lib/fonts";
|
||||
import "./globals.css";
|
||||
|
||||
import { RootProviders } from "@/providers/root-providers";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
/**
|
||||
* Athelas 字体加载
|
||||
* 原始资源:/Users/chase/Documents/cozsweet/fonts/Athelas-*.ttf
|
||||
* 放置位置:/public/fonts/Athelas-*.ttf
|
||||
*
|
||||
* 路径计算(`next/font/local` 要求相对路径从调用文件出发):
|
||||
* src/app/layout.tsx → ../../public/fonts/...
|
||||
*
|
||||
* 通过 `next/font/local` 自动 preload、压缩、inline。
|
||||
* 输出 CSS 变量 `--font-athelas`,由 `globals.css` 桥接到 Tailwind `font-athelas`。
|
||||
*/
|
||||
const athelas = localFont({
|
||||
src: [
|
||||
{
|
||||
path: "../../public/fonts/Athelas-Regular.ttf",
|
||||
weight: "400",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../../public/fonts/Athelas-Bold.ttf",
|
||||
weight: "700",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../../public/fonts/Athelas-BoldItalic.ttf",
|
||||
weight: "700",
|
||||
style: "italic",
|
||||
},
|
||||
],
|
||||
variable: "--font-athelas",
|
||||
display: "swap",
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "cozsweet",
|
||||
description: "cozsweet frontend (Next.js)",
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import localFont from "next/font/local";
|
||||
|
||||
/**
|
||||
* 全局字体配置(仅供服务端组件使用,例如 `src/app/layout.tsx`)。
|
||||
*
|
||||
* - `next/font/google` 与 `next/font/local` 在构建期完成 self-host、preload、
|
||||
* subset、inline,浏览器不会向 Google 发送请求,也不会产生 layout shift。
|
||||
* - 产出的 CSS 变量由 `globals.css` 桥接到 Tailwind(如 `font-sans`、`font-athelas`)。
|
||||
*
|
||||
* 注意:本文件**不**通过 `src/lib/index.ts` 桶导出,避免被误打进客户端 bundle。
|
||||
* 引用方式:`import { geistSans, geistMono, athelas } from "@/lib/fonts";`
|
||||
*/
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
/**
|
||||
* Athelas 本地字体。
|
||||
*
|
||||
* 原始资源:/Users/chase/Documents/cozsweet/fonts/Athelas-*.ttf
|
||||
* 放置位置:/public/fonts/Athelas-*.ttf
|
||||
*
|
||||
* 路径计算(`next/font/local` 要求相对路径从**调用文件**出发):
|
||||
* src/lib/fonts.ts → ../../public/fonts/...
|
||||
*/
|
||||
const athelas = localFont({
|
||||
src: [
|
||||
{
|
||||
path: "../../public/fonts/Athelas-Regular.ttf",
|
||||
weight: "400",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../../public/fonts/Athelas-Bold.ttf",
|
||||
weight: "700",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../../public/fonts/Athelas-BoldItalic.ttf",
|
||||
weight: "700",
|
||||
style: "italic",
|
||||
},
|
||||
],
|
||||
variable: "--font-athelas",
|
||||
display: "swap",
|
||||
});
|
||||
|
||||
export { geistSans, geistMono, athelas };
|
||||
Reference in New Issue
Block a user