-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9afa88
commit b1dc474
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use client"; | ||
import { Card, CardHeader, CardBody, CardFooter } from "@nextui-org/card"; | ||
import { Divider } from "@nextui-org/divider"; | ||
import { Link } from "@nextui-org/link"; | ||
|
||
export function Passage(props: { | ||
title: string; | ||
description: string; | ||
url: string; | ||
publishtime: string; | ||
}) { | ||
let publishtime = props.publishtime.replace("T", " ").replace("Z", ""); | ||
|
||
return ( | ||
<Card className="mt-5 p-1"> | ||
<CardHeader> | ||
<Link href={props.url}> | ||
<h2 | ||
dangerouslySetInnerHTML={{ __html: props.title }} | ||
className="font-bold" | ||
/> | ||
</Link> | ||
</CardHeader> | ||
<CardBody> | ||
<p dangerouslySetInnerHTML={{ __html: props.description }} /> | ||
</CardBody> | ||
<Divider /> | ||
<CardFooter> | ||
<p>{publishtime}</p> | ||
</CardFooter> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use client"; | ||
import { useEffect, useState } from "react"; | ||
|
||
import DefaultLayout from "@/layouts/default"; | ||
import { Passage } from "@/components/wppassage"; | ||
import { Skeleton } from "@nextui-org/skeleton"; | ||
import { Card } from "@nextui-org/card"; | ||
|
||
export default function NewsPage() { | ||
const [passages, setPassages] = useState([]); | ||
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
fetch("https://mc.hjfunny.site/wp-json/wp/v2/posts?per_page=20") | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
setPassages(data); | ||
setLoading(false); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<DefaultLayout> | ||
<section className="max-w-6xl mx-auto px-10 py-5 my-8"> | ||
<h1 className="text-lg font-bold">最近新闻</h1> | ||
|
||
{loading ? ( | ||
<Card className="mt-5 p-8"> | ||
<Skeleton className="rounded-lg mb-2"> | ||
<h2>Skeleton</h2> | ||
</Skeleton> | ||
<Skeleton className="rounded-lg"> | ||
<h2>Skeleton<br/>Skeleton<br/>Skeleton<br/>Skeleton</h2> | ||
</Skeleton> | ||
</Card> | ||
) : ( | ||
passages.map((passage) => ( | ||
<Passage | ||
key={passage["id"]} | ||
description={passage["excerpt"]["rendered"]} | ||
publishtime={passage["date"]} | ||
title={passage["title"]["rendered"]} | ||
url={`/post/${passage["slug"]}`} | ||
/> | ||
)) | ||
)} | ||
</section> | ||
</DefaultLayout> | ||
); | ||
} |