2024-08-16 10:41:36 +08:00
|
|
|
import { HomeCover } from "@/components/home-page/HomeCover";
|
2023-12-29 20:28:13 +08:00
|
|
|
import { Button } from "@/components/ui/button";
|
2024-01-06 20:53:18 +08:00
|
|
|
import { Separator } from "@/components/ui/separator";
|
2023-12-25 17:21:39 +08:00
|
|
|
import { Footer } from "@/components/utils/Footer";
|
2024-08-16 14:12:30 +08:00
|
|
|
import { ContentContainer, Page } from "@/components/utils/Layout";
|
2023-12-25 17:21:39 +08:00
|
|
|
import { NavBar } from "@/components/utils/NavBar";
|
|
|
|
|
import { PostList } from "@/components/utils/PostList";
|
|
|
|
|
import { SEO } from "@/components/utils/SEO";
|
|
|
|
|
import { LatestPostCountInHomePage } from "@/consts/consts";
|
|
|
|
|
import { Config } from "@/data/config";
|
|
|
|
|
import { sortedPosts } from "@/lib/post-process";
|
|
|
|
|
import { generateRSSFeed } from "@/lib/rss";
|
2024-09-26 16:48:47 +08:00
|
|
|
import type { TPostListItem } from "@/types/docs.type";
|
2024-08-14 12:57:22 +08:00
|
|
|
import type { GetStaticProps } from "next";
|
2023-12-25 17:21:39 +08:00
|
|
|
import Link from "next/link";
|
|
|
|
|
import { LuPenTool } from "react-icons/lu";
|
|
|
|
|
import { RiStarFill } from "react-icons/ri";
|
|
|
|
|
|
|
|
|
|
type HomePageProps = {
|
|
|
|
|
pinnedPostList: TPostListItem[];
|
|
|
|
|
latestPostList: TPostListItem[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function Home(props: HomePageProps) {
|
|
|
|
|
return (
|
|
|
|
|
<Page>
|
|
|
|
|
<SEO
|
|
|
|
|
coverURL={Config.PageCovers.websiteCoverURL}
|
2024-04-03 22:08:27 +08:00
|
|
|
description={`Welcome to the ${Config.Nickname}'s blog website. It's the website for recording thoughts for technology, life experience and so on.`}
|
|
|
|
|
title={`${Config.SiteTitle} - The personal blog for ${Config.Nickname}`}
|
2023-12-25 17:21:39 +08:00
|
|
|
/>
|
2024-01-09 16:48:48 +08:00
|
|
|
<NavBar />
|
2023-12-25 17:21:39 +08:00
|
|
|
<ContentContainer>
|
|
|
|
|
<HomeCover />
|
|
|
|
|
{props.pinnedPostList.length !== 0 && (
|
|
|
|
|
<div>
|
2024-01-06 20:53:18 +08:00
|
|
|
<Separator />
|
2024-08-14 12:57:22 +08:00
|
|
|
<h2 className={"caption-font my-5 flex justify-center font-bold text-2xl"}>
|
2023-12-25 17:21:39 +08:00
|
|
|
<RiStarFill className="mx-2 my-auto" />
|
|
|
|
|
{"PINNED POSTS"}
|
|
|
|
|
</h2>
|
2024-01-06 20:53:18 +08:00
|
|
|
<Separator />
|
2023-12-25 17:21:39 +08:00
|
|
|
<PostList data={props.pinnedPostList} />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{props.latestPostList.length !== 0 && (
|
|
|
|
|
<div>
|
2024-01-06 21:02:04 +08:00
|
|
|
<Separator />
|
2024-08-14 12:57:22 +08:00
|
|
|
<h2 className={"caption-font my-5 flex justify-center font-bold text-2xl"}>
|
2023-12-25 17:21:39 +08:00
|
|
|
<LuPenTool className="mx-2 my-auto" />
|
|
|
|
|
{"LATEST POSTS"}
|
|
|
|
|
</h2>
|
2024-01-06 20:53:18 +08:00
|
|
|
<Separator />
|
2023-12-25 17:21:39 +08:00
|
|
|
<PostList data={props.latestPostList} />
|
2024-01-08 18:18:21 +08:00
|
|
|
<Separator />
|
|
|
|
|
<div className="my-5 flex justify-end">
|
2023-12-29 20:28:13 +08:00
|
|
|
<Button asChild>
|
2024-04-03 22:08:27 +08:00
|
|
|
<Link className="font-bold" href="/posts">
|
2023-12-29 20:28:13 +08:00
|
|
|
{"MORE POSTS >"}
|
|
|
|
|
</Link>
|
|
|
|
|
</Button>
|
2023-12-25 17:21:39 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</ContentContainer>
|
|
|
|
|
<Footer />
|
|
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getStaticProps: GetStaticProps<HomePageProps> = async () => {
|
|
|
|
|
const pinnedPostList = sortedPosts.pinnedPostList;
|
|
|
|
|
const latestPostList = [];
|
|
|
|
|
|
|
|
|
|
for (let i = 0, j = 0; j < LatestPostCountInHomePage && i < sortedPosts.allPostList.length; i++) {
|
|
|
|
|
const postListItem = sortedPosts.allPostList[i];
|
|
|
|
|
if (!postListItem.frontMatter.noPrompt) {
|
|
|
|
|
latestPostList.push(postListItem);
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-26 11:08:42 +08:00
|
|
|
if (Config.RSSFeed?.enabled) {
|
|
|
|
|
await generateRSSFeed();
|
|
|
|
|
}
|
2023-12-25 17:21:39 +08:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
props: {
|
|
|
|
|
pinnedPostList: pinnedPostList,
|
|
|
|
|
latestPostList: latestPostList,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|