-
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.
feat: Add ViewPassagePage (Inital Version)
- Loading branch information
1 parent
16543ab
commit c980031
Showing
3 changed files
with
123 additions
and
6 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
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,27 @@ | ||
.content h1 { | ||
font-size: 1.5rem; /* 24px */ | ||
line-height: 2rem; /* 32px */ | ||
margin-top: 0.5rem; /* 8px */ | ||
margin-bottom: 0.25rem; /* 4px */ | ||
font-weight: 700; | ||
} | ||
|
||
.content h2 { | ||
font-size: 1.25rem; /* 20px */ | ||
line-height: 1.75rem; /* 28px */ | ||
margin-top: 0.5rem; /* 8px */ | ||
margin-bottom: 0.25rem; /* 4px */ | ||
font-weight: 700; | ||
} | ||
|
||
.content h3 { | ||
font-size: 1.125rem; /* 18px */ | ||
line-height: 1.75rem; /* 28px */ | ||
margin-top: 0.5rem; /* 8px */ | ||
margin-bottom: 0.25rem; /* 4px */ | ||
font-weight: 700; | ||
} | ||
|
||
.content a { | ||
color: #338cf1; | ||
} |
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,82 @@ | ||
import { Card } from "@nextui-org/card"; | ||
import { Skeleton } from "@nextui-org/skeleton"; | ||
import { useRouter } from "next/router"; | ||
import { useEffect, useState } from "react"; | ||
|
||
import DefaultLayout from "@/layouts/default"; | ||
import { siteConfig } from "@/config/site"; | ||
|
||
import styles from "./viewpassage.module.css"; | ||
|
||
export default function ViewPassagePage() { | ||
const router = useRouter(); | ||
const { id } = router.query; | ||
|
||
const [post, setPost] = useState(null); | ||
const [loadStat, setLoadStat] = useState("loading"); | ||
|
||
useEffect(() => { | ||
if (id) { | ||
fetch(`https://mc.hjfunny.site/wp-json/wp/v2/posts/${id}`) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
setPost(data); | ||
setLoadStat("loaded"); | ||
if (post) { | ||
document.title = `${post["title"]["rendered"]} - ${siteConfig.name}`; | ||
} | ||
}) | ||
.catch(() => { | ||
setLoadStat("error"); | ||
}); | ||
} | ||
}, [id]); | ||
|
||
return ( | ||
<DefaultLayout | ||
title={ | ||
loadStat == "loaded" && post ? post["title"]["rendered"] : "查看文章" | ||
} | ||
> | ||
<section className="max-w-6xl mx-auto px-10 py-5 my-8"> | ||
{loadStat == "loading" ? ( | ||
<> | ||
<Skeleton className="rounded-lg mb-2"> | ||
<h1 className="text-lg font-bold">Skeleton</h1> | ||
</Skeleton> | ||
<Card className="mt-5 p-5"> | ||
<Skeleton className="rounded-lg"> | ||
<h2> | ||
Skeleton | ||
<br /> | ||
Skeleton | ||
<br /> | ||
Skeleton | ||
<br /> | ||
Skeleton | ||
</h2> | ||
</Skeleton> | ||
</Card> | ||
</> | ||
) : loadStat == "loaded" && post ? ( | ||
<> | ||
<h1 className="text-lg font-bold mb-2"> | ||
{post["title"]["rendered"]} | ||
</h1> | ||
<p>{String(post["date"]).replace("T", " ")}</p> | ||
<Card className="mt-5 p-5"> | ||
<div | ||
className={styles.content} | ||
dangerouslySetInnerHTML={{ | ||
__html: post["content"]["rendered"], | ||
}} | ||
/> | ||
</Card> | ||
</> | ||
) : ( | ||
<></> | ||
)} | ||
</section> | ||
</DefaultLayout> | ||
); | ||
} |