From b75b186955109d7fcba6867ad35a4726b0446ed2 Mon Sep 17 00:00:00 2001 From: Nooc Date: Sat, 19 Oct 2024 14:50:35 +0800 Subject: [PATCH] Display latest posts in home page --- app/[lang]/page.tsx | 60 ++++++++++++++++++++++++++++++--------- app/[lang]/works/page.tsx | 2 +- dictionaries/en.ts | 13 +++++---- dictionaries/zh.ts | 13 +++++---- 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/app/[lang]/page.tsx b/app/[lang]/page.tsx index 707d33f..5474eab 100644 --- a/app/[lang]/page.tsx +++ b/app/[lang]/page.tsx @@ -4,6 +4,10 @@ import ProfileCard from "../../components/profile-card"; import Image from "next/image"; import { twMerge } from "tailwind-merge"; import { getDictionary } from "@/dictionaries"; +import { posts } from "@/.velite"; +import Link from "next/link"; +import { CalendarDaysIcon } from "@heroicons/react/24/solid"; +import { displayDate } from "@/lib/date"; export const runtime = "edge"; @@ -49,6 +53,13 @@ function Label({ ); } +function getLatestPosts(lang: string) { + return posts + .sort((p1, p2) => new Date(p2.date).getTime() - new Date(p1.date).getTime()) + .filter((post) => !post.draft && post.lang === lang) + .slice(0, 2); +} + export default async function Home({ params, }: { @@ -57,6 +68,7 @@ export default async function Home({ }; }) { const dictionary = await getDictionary(params.lang); + const latestPosts = getLatestPosts(params.lang); return (
@@ -77,29 +89,49 @@ export default async function Home({ -
- {dictionary.labels.icon(work.name)} -
- {work.name} -
- {new URL(work.link).host} -
-
+ {work.name} +
+ {new URL(work.link).host}
- {work.summary} + {work.summary} + {dictionary.labels.icon(work.name)} ))}
+ +
+ +
    + {latestPosts.map((post) => ( +
  • + +

    {post.title}

    + +

    {post.description}

    +
    +
    + + {displayDate(post.date, params.lang)} +
    +
    +
  • + ))} +
+
+
diff --git a/app/[lang]/works/page.tsx b/app/[lang]/works/page.tsx index c5d3c9b..74bd255 100644 --- a/app/[lang]/works/page.tsx +++ b/app/[lang]/works/page.tsx @@ -52,7 +52,7 @@ export default async function WorksPage({ > {work.image ? ( {dictionary.labels.icon(work.name)} diff --git a/dictionaries/en.ts b/dictionaries/en.ts index 8cbfe34..e1146b7 100644 --- a/dictionaries/en.ts +++ b/dictionaries/en.ts @@ -13,8 +13,8 @@ import AssisChat from "../public/static/assischat.webp"; import lofyee from "../public/static/lofyee.webp"; import subnooc from "../public/static/subnooc.webp"; import youminco from "../public/static/youminco.webp"; -import SparkMemosLogo from '../public/static/sparkmemos.webp'; -import CassetteOneLogo from '../public/static/cassette-one.webp'; +import SparkMemosLogo from "../public/static/sparkmemos.webp"; +import CassetteOneLogo from "../public/static/cassette-one.webp"; const dictionary = { meta: { @@ -71,6 +71,7 @@ A fan of Serverless. home: "Home", works: "Works", posts: "Blog", + latestPosts: "Latest Posts", noocWorks: "Nooc's Works", doing: "Doing", playing: "Playing", @@ -217,16 +218,18 @@ A fan of Serverless. icon: EnvelopeIcon, }, ], - postAdvertisements:[ + postAdvertisements: [ { title: "Support me", - description: "Spark Memos is a concise note-taking app for capturing ideas, inspirations, or for later reading and book notes.", + description: + "Spark Memos is a concise note-taking app for capturing ideas, inspirations, or for later reading and book notes.", icon: SparkMemosLogo, link: "https://sparkmemos.com", }, { title: "Support me", - description: "CassetteOne is a retro design cassette white noise and music player for iOS.", + description: + "CassetteOne is a retro design cassette white noise and music player for iOS.", icon: CassetteOneLogo, link: "https://cassette.one", }, diff --git a/dictionaries/zh.ts b/dictionaries/zh.ts index 5424c8e..5b1ee46 100644 --- a/dictionaries/zh.ts +++ b/dictionaries/zh.ts @@ -13,8 +13,8 @@ import AssisChat from "../public/static/assischat.webp"; import lofyee from "../public/static/lofyee.webp"; import subnooc from "../public/static/subnooc.webp"; import youminco from "../public/static/youminco.webp"; -import SparkMemosLogo from '../public/static/sparkmemos.webp'; -import CassetteOneLogo from '../public/static/cassette-one.webp'; +import SparkMemosLogo from "../public/static/sparkmemos.webp"; +import CassetteOneLogo from "../public/static/cassette-one.webp"; const dictionary = { meta: { @@ -70,6 +70,7 @@ Serverless 爱好者。 home: "主页", works: "作品", posts: "博客", + latestPosts: "最新博客", noocWorks: "Nooc的作品", doing: "在做什么", playing: "在玩什么", @@ -215,16 +216,18 @@ Serverless 爱好者。 postAdvertisements: [ { title: "支持我", - description: "「星火记」是一个简洁的短笔记应用,可以用来记录灵感、想法,或者是用于稍后阅读、读书笔记等。", + description: + "「星火记」是一个简洁的短笔记应用,可以用来记录灵感、想法,或者是用于稍后阅读、读书笔记等。", icon: SparkMemosLogo, link: "https://sparkmemos.com", }, { title: "支持我", - description: "「CassetteOne」是一个模拟磁带机设计的复古风格白噪音和音乐播放器。", + description: + "「CassetteOne」是一个模拟磁带机设计的复古风格白噪音和音乐播放器。", icon: CassetteOneLogo, link: "https://cassette.one", - } + }, ], };