Files
lixiyu-net/pages/index.tsx

94 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-12-25 17:21:39 +08:00
import { HomeCover } from "@/components/homepage/HomeCover";
import { ContentContainer, Page } from "@/components/layouts";
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";
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";
import { TPostListItem } from "@/types/post-list";
import { GetStaticProps } from "next";
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
/>
<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-12 13:39:19 +08:00
<h2 className={`my-5 flex justify-center text-2xl font-bold caption-font`}>
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-12 13:39:19 +08:00
<h2 className={`my-5 flex justify-center text-2xl font-bold caption-font`}>
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">
<Button asChild>
2024-04-03 22:08:27 +08:00
<Link className="font-bold" href="/posts">
{"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++;
}
}
if (Config.RSSFeed?.enabled) {
await generateRSSFeed();
}
2023-12-25 17:21:39 +08:00
return {
props: {
pinnedPostList: pinnedPostList,
latestPostList: latestPostList,
},
};
};