Skip to content

Commit 319d076

Browse files
committed
test: 文章meta
1 parent 94a875b commit 319d076

File tree

8 files changed

+32
-1
lines changed

8 files changed

+32
-1
lines changed

config/seo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const seo = {
2-
title: 'zhw | fe',
2+
title: 'home | zhw',
33
description: '我是zhw,欢迎来到我的博客',
44
url: new URL(
55
process.env.NODE_ENV === 'production'

markdown/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"path": "react19.md",
1010
"title": "react19",
1111
"tag": "随笔/生活",
12+
"summary": "这篇文章记录了react19相关的一些内容",
1213
"coverImage": "https://p6-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/0b76076eab124179816d68b846280cdc~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgTWVnYXRyb25LaW5n:q75.awebp?rk3s=f64ab15b&x-expires=1731736114&x-signature=3ggdE9od5WvMZaVJ7VFlQtt48rA%3D"
1314
}
1415
]

src/app/(app)/about/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NormalContainer } from '@/components/layout/container/Normal';
55

66
export const metadata: Metadata = {
77
title: '关于我',
8+
description: '但愿人长久,千里共婵娟',
89
};
910

1011
export default async function (props: PropsWithChildren) {

src/app/(app)/friends/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NormalContainer } from '@/components/layout/container/Normal';
55

66
export const metadata: Metadata = {
77
title: '朋友们',
8+
description: '海内存知己,天涯若比邻',
89
};
910

1011
export default async function (props: PropsWithChildren) {

src/app/(app)/list/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import React from 'react';
2+
import { Metadata } from 'next';
23

34
import AnimatedPostItem from './AnimatedPostItem';
45

56
import { NormalContainer } from '@/components/layout/container/Normal';
67
import { buildPostData } from '@/core';
78

9+
export const metadata: Metadata = {
10+
title: '文稿',
11+
description: '文章列表',
12+
};
13+
814
const ArticleList: React.FC = () => {
915
const { postDataList } = buildPostData();
1016

src/app/(app)/notes/[nid]/page.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use server';
22

3+
import { Metadata } from 'next';
4+
35
import {
46
NoteTitle,
57
NoteDateMeta,
@@ -18,6 +20,22 @@ const { postDataMap } = buildPostData();
1820

1921
export type PageInnerProps = { postData: PostItemType };
2022

23+
export const generateMetadata = async ({ params }: { params: any }): Promise<Metadata> => {
24+
try {
25+
const { nid } = params;
26+
27+
const postData = postDataMap[nid];
28+
const { title, summary } = postData;
29+
30+
return {
31+
title: { absolute: title },
32+
description: summary,
33+
} satisfies Metadata;
34+
} catch {
35+
return {};
36+
}
37+
};
38+
2139
export default async function Page({ params }: { params: Record<string, any> }) {
2240
const { nid } = params;
2341
const postData = postDataMap[nid];

src/app/(app)/projects/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NormalContainer } from '@/components/layout/container/Normal';
55

66
export const metadata: Metadata = {
77
title: '看看我在做啥',
8+
description: '一些小玩具',
89
};
910

1011
export default async function (props: PropsWithChildren) {

src/core/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ export type PostItem = {
1616
createdAt: Date | null;
1717
modified: boolean;
1818
coverImage: string;
19+
summary?: string;
1920
};
2021

2122
export type PostJsonType = {
2223
path: string;
2324
title: string;
2425
tag: string;
2526
coverImage: string;
27+
summary?: string;
2628
};
2729
export type PostMap = Record<string, PostItem>;
2830

@@ -44,6 +46,7 @@ export function buildPostData() {
4446
itemInfo.tag = item.tag;
4547
itemInfo.path = item.path.replace('.md', '');
4648
itemInfo.rawFilePath = `./${item.path}`;
49+
itemInfo.summary = item.summary;
4750
itemInfo.coverImage = item.coverImage.startsWith('http')
4851
? item.coverImage
4952
: `/postCoverImage/${item.coverImage}`;

0 commit comments

Comments
 (0)