Skip to content

Commit 3e31b14

Browse files
committed
feat: 优化部分代码,准备实现获取markdwon
1 parent e64708c commit 3e31b14

File tree

10 files changed

+64
-64
lines changed

10 files changed

+64
-64
lines changed

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import { TextUpTransitionView } from '@/components/ui/transition/TextUpTransitio
88
import { SocialIcon } from '@/components/modules/home/SocialIcon';
99
import {
1010
FaSolidFeatherAlt,
11-
FaSolidHistory,
1211
FaSolidUserFriends,
13-
IcTwotoneSignpost,
1412
MdiFlask,
15-
MdiLightbulbOn20,
1613
RMixPlanet,
1714
} from '@/components/icons/menu-collection';
1815
import { cn } from '@/lib/helper';
@@ -21,32 +18,15 @@ import { FocusCards } from '@/components/ui/focus-cards.tsx';
2118
const windsock = [
2219
{
2320
title: '文稿',
24-
path: '/posts',
25-
type: 'Post',
26-
subMenu: [],
27-
icon: IcTwotoneSignpost,
28-
},
29-
{
30-
title: '手记',
3121
type: 'Note',
32-
path: '/notes',
22+
path: '/list',
3323
icon: FaSolidFeatherAlt,
3424
},
35-
{
36-
title: '度过的时光',
37-
icon: FaSolidHistory,
38-
path: '/timeline',
39-
},
4025
{
4126
title: '朋友们',
4227
icon: FaSolidUserFriends,
4328
path: '/friends',
4429
},
45-
{
46-
title: '写下一点思考',
47-
icon: MdiLightbulbOn20,
48-
path: '/thinking',
49-
},
5030
{
5131
title: '看看我做些啥',
5232
icon: MdiFlask,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function Friends() {
1010
return (
1111
<div>
1212
<header className="prose prose-p:my-2 font-mono">
13-
<h1>朋友们</h1>
13+
<h2>朋友们</h2>
1414
<h3>海内存知己,天涯若比邻</h3>
1515
</header>
1616

@@ -24,16 +24,16 @@ export default function Friends() {
2424
const FriendCardList = ({ data }: { data: FriendModel[] }) => (
2525
<div className="grid grid-cols-2 gap-6 md:grid-cols-3">
2626
{data.map((friendModel) => {
27-
return <FriendCard friendModel={friendModel} />;
27+
return <FriendCard key={friendModel.url} friendModel={friendModel} />;
2828
})}
2929
</div>
3030
);
31+
3132
const FriendCard = ({ friendModel }: { friendModel: FriendModel }) => {
3233
const [enter, setEnter] = useState(false);
3334

3435
return (
3536
<m.div
36-
key={friendModel.name}
3737
role="link"
3838
aria-label={`Go to ${friendModel.name}'s website`}
3939
className="relative flex flex-col items-center justify-center cursor-pointer"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// AnimatedPostItem.tsx
2+
'use client';
3+
4+
import React from 'react';
5+
import { m } from 'framer-motion';
6+
7+
import { PostItem } from '@/components/modules/list/PostItem';
8+
9+
interface AnimatedPostItemProps {
10+
item: {
11+
id: number;
12+
title: string;
13+
content: string;
14+
};
15+
index: number;
16+
}
17+
18+
const AnimatedPostItem: React.FC<AnimatedPostItemProps> = ({ item, index }) => {
19+
return (
20+
<m.li
21+
initial={{ y: 50, opacity: 0.01 }}
22+
animate={{
23+
y: 0,
24+
opacity: 1,
25+
transition: {
26+
delay: index * 0.1,
27+
type: 'spring',
28+
damping: 10,
29+
stiffness: 100,
30+
},
31+
}}
32+
key={item.id}
33+
>
34+
<PostItem data={item} />
35+
</m.li>
36+
);
37+
};
38+
39+
export default AnimatedPostItem;

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use client';
2-
31
import React from 'react';
4-
import { m } from 'framer-motion';
2+
3+
import AnimatedPostItem from './AnimatedPostItem';
54

65
import { NormalContainer } from '@/components/layout/container/Normal';
7-
import { PostItem } from '@/components/modules/list/PostItem';
86

97
// 假数据
108
const mockData = [
@@ -14,7 +12,6 @@ const mockData = [
1412
{ id: 12, title: '文章标题 1', content: '这是文章内容 1' },
1513
{ id: 22, title: '文章标题 2', content: '这是文章内容 2' },
1614
{ id: 32, title: '文章标题 3', content: '这是文章内容 3' },
17-
1815
// 更多假数据
1916
];
2017

@@ -23,22 +20,7 @@ const ArticleList: React.FC = () => {
2320
<NormalContainer>
2421
<ul>
2522
{mockData.map((item, index) => (
26-
<m.li
27-
initial={{ y: 50, opacity: 0.01 }}
28-
animate={{
29-
y: 0,
30-
opacity: 1,
31-
transition: {
32-
delay: index * 0.1,
33-
type: 'spring',
34-
damping: 10,
35-
stiffness: 100,
36-
},
37-
}}
38-
key={item.id}
39-
>
40-
<PostItem data={item} />
41-
</m.li>
23+
<AnimatedPostItem key={item.id} item={item} index={index} />
4224
))}
4325
</ul>
4426
</NormalContainer>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function Projects() {
3535
const ProjectCardList = ({ data }: { data: ProjectModel[] }) => (
3636
<div className="grid min-w-0 grid-cols-2 gap-6 lg:grid-cols-3">
3737
{data.map((projectModel) => {
38-
return <ProjectCard project={projectModel} />;
38+
return <ProjectCard key={projectModel.name} project={projectModel} />;
3939
})}
4040
</div>
4141
);
@@ -52,9 +52,9 @@ const ProjectCard = ({ project }: { project: ProjectModel }) => {
5252
name={project.name}
5353
/>
5454
<span className="flex shrink-0 grow flex-col gap-2 text-left">
55-
<h4 className="m-0 text-balance p-0 text-center font-medium md:text-left">
55+
<h2 className="m-0 text-balance p-0 text-center font-medium md:text-left">
5656
{project.name}
57-
</h4>
57+
</h2>
5858
<span className="line-clamp-5 text-balance text-center text-sm md:line-clamp-4 md:text-left lg:line-clamp-2">
5959
{project.desc}
6060
</span>

src/app/layout.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ export const viewport: Viewport = {
5050
],
5151
width: 'device-width',
5252
initialScale: 1,
53-
userScalable: false,
5453
minimumScale: 1,
55-
maximumScale: 1,
54+
maximumScale: 5,
5655
};
5756

5857
export default async function RootLayout({ children }: PropsWithChildren) {

src/components/modules/home/BlogPostCard/BlogPostCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import Image from 'next/image';
23

34
type BlogPostCardProps = {
45
title: string;
@@ -30,7 +31,7 @@ const BlogPostCard: React.FC<BlogPostCardProps> = ({
3031
<div className="relative z-10 flex flex-col justify-between h-full p-6">
3132
{/* 顶部头像 */}
3233
<div className="flex justify-start items-center mb-4">
33-
<img src="/path-to-avatar.png" alt="avatar" className="h-10 w-10 rounded-full" />
34+
<Image src="/path-to-avatar.png" alt="avatar" className="h-10 w-10 rounded-full" />
3435
</div>
3536

3637
{/* 中间主要标题 */}

src/components/modules/toc/TocTree.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ const MemoedItem = memo<{
159159
const { heading, isActive, onClick, rootDepth } = props;
160160
const itemRef = useRef<HTMLLIElement>(null);
161161

162-
console.log(heading);
163-
164162
return (
165163
<m.li
166164
initial={{ x: 60, opacity: 0 }}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import Image from 'next/image';
2+
3+
// https://github.com/vercel/next.js/discussions/18474
14
export const MarkdownImage = (props: { src: string; alt?: string }) => {
25
return (
3-
<span className="flex w-full flex-col items-center border-none mdImg">
4-
<img src={props.src} alt={props.alt} loading="lazy" className="mx-auto w-[50%] rounded-md" />
5-
<span className=" w-full">居中文本</span>
6+
<span className=" relative w-full border-none">
7+
<Image
8+
width={0}
9+
height={0}
10+
sizes="100vw"
11+
src={props.src}
12+
alt={props.alt ?? 'image'}
13+
className=" w-full h-auto rounded-md"
14+
/>
615
</span>
716
);
817
};

src/styles/mdContainer.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
.with-indent blockquote .paragraph > span {
1919
margin-left: 0 !important;
2020
}
21-
.mdImg span {
22-
display: inline-block !important;
23-
margin-left: 0 !important;
24-
margin-right: 0 auto;
25-
padding: 0;
26-
text-align: center;
27-
}
28-
2921
.with-indent blockquote .paragraph:first-child::first-letter {
3022
float: none !important;
3123
font-size: inherit !important;

0 commit comments

Comments
 (0)