[upgrade] Abstract components on the page into subcomponents
This commit is contained in:
19
components/about-page/Introduction.tsx
Normal file
19
components/about-page/Introduction.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
export const Introduction = () => {
|
||||
return (
|
||||
<div className={"my-5 justify-center content-font md:flex md:space-x-10"}>
|
||||
<div className="my-auto flex md:w-1/3">
|
||||
<img alt="my-profile" className="mx-auto my-auto max-h-[23rem] rounded-lg" src="/images/profile.webp" />
|
||||
</div>
|
||||
<div className="my-auto md:w-1/3">
|
||||
<div className="mt-5 mb-3 font-bold text-3xl">Hi, there👋</div>I am a student / entrepreneur / engineer (Your
|
||||
profession) majoring in (Your Research Field) born in XXXX (Your birth year)
|
||||
<br />
|
||||
<br />
|
||||
My main research interests includes XXXX
|
||||
<br />
|
||||
<br />
|
||||
Additionally, I am also interested in XXXX.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
30
components/about-page/PersonalStatus.tsx
Normal file
30
components/about-page/PersonalStatus.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Config } from "@/data/config";
|
||||
import Link from "next/link";
|
||||
|
||||
export const PersonalStatus = () => {
|
||||
return (
|
||||
<ul className="mx-auto my-10 list-disc px-5 md:w-2/3">
|
||||
{Config.SocialLinks.github && (
|
||||
<li className="my-2">
|
||||
{"📕 Check out my github profile at "}
|
||||
<Link className="underline" href={`https://github.com/${Config.SocialLinks.github}`} target="_blank">
|
||||
Github
|
||||
</Link>
|
||||
</li>
|
||||
)}
|
||||
<li className="my-2">🖥️ Programming stack: TypeScript, JavaScript, C++, C, Rust, Go and so on.</li>
|
||||
<li className="my-2">🤝 I am looking for friends who are fund of XXXX</li>
|
||||
{Config.SocialLinks.twitter && (
|
||||
<li className="my-2">
|
||||
{"📫 How to reach me on Twitter: "}
|
||||
<Link className="link" href={`https://twitter.com/${Config.SocialLinks.twitter}`} target="_blank">
|
||||
{Config.SocialLinks.twitter}
|
||||
</Link>
|
||||
</li>
|
||||
)}
|
||||
<li className="my-2">Language : 汉语 / English / 한국어 / 日本語 </li>
|
||||
<li className="my-2">Pronouns : Male / Female / MTF / FTM / And Others</li>
|
||||
<li className="my-2">From : Your Country, State / Province</li>
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
29
components/friend-links-page/FriendLinksList.tsx
Normal file
29
components/friend-links-page/FriendLinksList.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Config } from "@/data/config";
|
||||
import { FriendsList } from "@/data/friends";
|
||||
import type { TFriendItem } from "@/types/friend.type";
|
||||
import { nanoid } from "nanoid";
|
||||
import Link from "next/link";
|
||||
|
||||
export const FriendLinkList = (props: { friends: TFriendItem[] }) => {
|
||||
return (
|
||||
<div>
|
||||
<div className={"my-5 flex flex-wrap justify-center text-2xl content-font"}>
|
||||
{FriendsList.map((item) => (
|
||||
<Link className="mx-2 p-2 underline underline-offset-4" href={item.url} key={nanoid()} target="_blank">
|
||||
{item.title}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="my-2 flex flex-col justify-start text-base">
|
||||
<div className="mx-auto">
|
||||
{"Welcome to exchange our friend links and every high-quality blog websites are welcomed. "}
|
||||
<Link className="underline" href={`mailto:${Config.SocialLinks.email}`}>
|
||||
{"Email me please"}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
29
components/post-list-page/TagsList.tsx
Normal file
29
components/post-list-page/TagsList.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/ui/accordion";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import Link from "next/link";
|
||||
import { nanoid } from "nanoid";
|
||||
import type { TTagListItem } from "@/types/docs.type";
|
||||
|
||||
export const TagsList = (props: { tagsList: TTagListItem[] }) => {
|
||||
return (
|
||||
<Accordion collapsible type="single">
|
||||
<AccordionItem className="border-t" value="item-1">
|
||||
<AccordionTrigger className="font-bold hover:no-underline">{"TAG FILTER"}</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<Separator />
|
||||
<div className={"my-5 flex flex-wrap justify-center text-wrap px-2 text-sm"}>
|
||||
{props.tagsList.map((item) => (
|
||||
<Link
|
||||
className="m-1 my-auto p-1 font-bold text-gray-700 underline decoration-2 underline-offset-[5px] hover:text-black dark:text-gray-300 dark:hover:text-white"
|
||||
href={`/tags/${item.name}`}
|
||||
key={`tags-${nanoid()}`}
|
||||
>
|
||||
{`${item.name} (${item.count})`}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
);
|
||||
};
|
||||
@@ -1,10 +1,14 @@
|
||||
import seal from "@/assets/icons/seal.svg";
|
||||
import { Config } from "@/data/config";
|
||||
|
||||
export const BottomCard = () => {
|
||||
return (
|
||||
<div className="flex w-full flex-col justify-center p-8">
|
||||
<img alt={Config.AuthorName} className="mx-auto h-24 w-24 rounded-full" src={Config.AvatarURL} />
|
||||
<p className="mx-auto mt-5 content-font">{Config.Sentence}</p>
|
||||
<div className="flex w-full select-none flex-col justify-center p-8">
|
||||
<div
|
||||
className="mx-auto h-24 w-24"
|
||||
style={{ backgroundImage: `url(${seal.src})`, backgroundRepeat: "no-repeat", backgroundSize: "contain" }}
|
||||
/>
|
||||
<p className={"mx-auto mt-5 content-font"}>{Config.Sentence}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
|
||||
import { useActiveHeading } from "@/hooks/useActiveHeading";
|
||||
import useDrawerTOCState from "@/stores/useDrawerTOCState";
|
||||
import type { TTOCItem } from "@/types/docs.type";
|
||||
import type { TPostTOCItem } from "@/types/docs.type";
|
||||
import Link from "next/link";
|
||||
import { MdMenuBook } from "react-icons/md";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export const DrawerTOC = (props: { data: TTOCItem[] }) => {
|
||||
export const DrawerTOC = (props: { data: TPostTOCItem[] }) => {
|
||||
const isTOCOpen = useDrawerTOCState((state) => state.isOpen);
|
||||
const setIsTOCOpen = useDrawerTOCState((state) => state.changeDrawerTOCOpen);
|
||||
const activeId = useActiveHeading(props.data.map((item) => `#${item.anchorId}`));
|
||||
@@ -16,13 +16,18 @@ export const DrawerTOC = (props: { data: TTOCItem[] }) => {
|
||||
className="fixed right-5 bottom-16 border border-gray-700 bg-white shadow-xl dark:border-gray-500 dark:bg-black"
|
||||
title="Open the table of contents"
|
||||
>
|
||||
<div className="p-1 font-bold" onClick={() => setIsTOCOpen(!isTOCOpen)} title="Open the table of contents">
|
||||
<div
|
||||
className="p-1 font-bold"
|
||||
onClick={() => setIsTOCOpen(!isTOCOpen)}
|
||||
onKeyDown={() => {}}
|
||||
title="Open the table of contents"
|
||||
>
|
||||
<MdMenuBook className="text-3xl" />
|
||||
</div>
|
||||
</SheetTrigger>
|
||||
<SheetContent side={"left"}>
|
||||
<SheetContent side={"right"}>
|
||||
<SheetHeader>
|
||||
<SheetTitle className="mt-8 font-bold">{"TABLE OF CONTENTS"}</SheetTitle>
|
||||
<SheetTitle className="mt-8 text-center font-bold text-base">{"TABLE OF CONTENTS"}</SheetTitle>
|
||||
</SheetHeader>
|
||||
<ul className="flat-scrollbar flat-scrollbar-normal my-3 flex h-[70vh] flex-col overflow-y-auto">
|
||||
{props.data?.map((item) => (
|
||||
|
||||
26
components/reader-page/MorePostLinks.tsx
Normal file
26
components/reader-page/MorePostLinks.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { TPostListItem } from "@/types/docs.type";
|
||||
import Link from "next/link";
|
||||
|
||||
export const MorePostLinks = (props: {
|
||||
prevPostListItem: TPostListItem | null;
|
||||
nextPostListItem: TPostListItem | null;
|
||||
}) => {
|
||||
return (
|
||||
<ul className="my-5 flex list-disc flex-col justify-center px-5">
|
||||
{props.prevPostListItem && (
|
||||
<li className="my-1">
|
||||
<Link className=" hover:text-sky-600 dark:hover:text-sky-500" href={`/blog/${props.prevPostListItem?.id}`}>
|
||||
{props.prevPostListItem?.frontMatter.title}
|
||||
</Link>
|
||||
</li>
|
||||
)}
|
||||
{props.nextPostListItem && (
|
||||
<li className="my-1">
|
||||
<Link className=" hover:text-sky-600 dark:hover:text-sky-500" href={`/blog/${props.nextPostListItem?.id}`}>
|
||||
{props.nextPostListItem?.frontMatter.title}
|
||||
</Link>
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
@@ -11,7 +11,6 @@ export const PostComments = (props: { postId: string }) => {
|
||||
category={Config.Giscus.category}
|
||||
categoryId={Config.Giscus.categoryId}
|
||||
emitMetadata="0"
|
||||
id={props.postId}
|
||||
inputPosition="top"
|
||||
lang="en"
|
||||
loading="eager"
|
||||
|
||||
@@ -3,7 +3,7 @@ export const PostCover = (props: { coverURL: string }) => {
|
||||
<div
|
||||
className="mt-0 mb-8 flex w-full justify-center rounded-md"
|
||||
style={{
|
||||
aspectRatio: "5/2",
|
||||
aspectRatio: "5/1",
|
||||
background: `url(${props.coverURL})`,
|
||||
backgroundSize: "cover",
|
||||
backgroundRepeat: "no-repeat",
|
||||
|
||||
70
components/reader-page/PostRender.tsx
Normal file
70
components/reader-page/PostRender.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import { MDXComponentsSet } from "@/components/mdx";
|
||||
import { normalizeDate } from "@/lib/date";
|
||||
import type { TPostFrontmatter, TPostListItem, TPostTOCItem } from "@/types/docs.type";
|
||||
import { nanoid } from "nanoid";
|
||||
import { MDXRemote, type MDXRemoteSerializeResult } from "next-mdx-remote";
|
||||
import Link from "next/link";
|
||||
|
||||
export const PostRender = (props: {
|
||||
compiledSource: MDXRemoteSerializeResult;
|
||||
tocList: TPostTOCItem[];
|
||||
frontMatter: TPostFrontmatter;
|
||||
postId: string;
|
||||
nextPostListItem: TPostListItem | null;
|
||||
prevPostListItem: TPostListItem | null;
|
||||
}) => {
|
||||
const compiledSource = props.compiledSource;
|
||||
return (
|
||||
<div className="typesetting">
|
||||
<div className="border-black border-b-2 pb-1 dark:border-gray-300">
|
||||
<div
|
||||
className={
|
||||
"caption-font my-2 flex justify-center whitespace-normal break-words font-bold text-[1.8rem] text-black leading-[2.1rem] dark:text-white"
|
||||
}
|
||||
>
|
||||
{props.frontMatter?.title}
|
||||
</div>
|
||||
{props.frontMatter?.subtitle && (
|
||||
<div className={"my-1 flex justify-center font-bold text-xl content-font"}>{props.frontMatter.subtitle}</div>
|
||||
)}
|
||||
<div className="my-1 flex justify-center text-sm italic">{normalizeDate(props.frontMatter?.time)}</div>
|
||||
{props.frontMatter?.summary && (
|
||||
<p
|
||||
className={
|
||||
"my-4 border-gray-400 border-l-4 bg-gray-100 py-5 pr-2 pl-5 text-[16px] text-gray-800 content-font dark:border-gray-600 dark:bg-gray-900 dark:text-gray-300"
|
||||
}
|
||||
>
|
||||
{props.frontMatter?.summary}
|
||||
</p>
|
||||
)}
|
||||
{props.frontMatter.tags && (
|
||||
<div className={"flex flex-wrap border-black border-t-2 pt-1 dark:border-gray-300"}>
|
||||
{props.frontMatter.tags.map((tagName) => (
|
||||
<Link
|
||||
className="not-prose my-1 mr-2 border-2 border-black px-2 py-1 font-bold text-gray-700 text-xs hover:text-black dark:border-gray-300 dark:text-gray-300 dark:hover:text-gray-200"
|
||||
href={`/tags/${tagName}`}
|
||||
key={`tags-${nanoid()}`}
|
||||
>
|
||||
{tagName}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-wrap border-gray-500 content-font ${!props.frontMatter.allowShare ? "select-none" : ""}`}
|
||||
// {...handleLeftSwipe}
|
||||
>
|
||||
{compiledSource && (
|
||||
<MDXRemote
|
||||
compiledSource={compiledSource.compiledSource}
|
||||
// @ts-ignore
|
||||
components={MDXComponentsSet}
|
||||
frontmatter={compiledSource.frontmatter}
|
||||
scope={compiledSource.scope}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,13 +1,13 @@
|
||||
import { useActiveHeading } from "@/hooks/useActiveHeading";
|
||||
import type { TTOCItem } from "@/types/docs.type";
|
||||
import type { TPostTOCItem } from "@/types/docs.type";
|
||||
import Link from "next/link";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export const TOC = (props: { data: TTOCItem[] }) => {
|
||||
export const TOC = (props: { data: TPostTOCItem[] }) => {
|
||||
const activeId = useActiveHeading(props.data.map((item) => `#${item.anchorId}`));
|
||||
|
||||
return (
|
||||
<div className="mx-5">
|
||||
<div className="mr-5">
|
||||
<div className="border-gray-500 border-t-2 border-b-2 p-2 text-center font-bold text-lg">
|
||||
{"TABLE OF CONTENTS"}
|
||||
</div>
|
||||
|
||||
43
components/search-page/SearchInput.tsx
Normal file
43
components/search-page/SearchInput.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { isEmptyString } from "@/lib/utils";
|
||||
import { type ChangeEvent, type KeyboardEvent, useEffect, useState } from "react";
|
||||
|
||||
export const SearchInput = (props: {
|
||||
handleSearch: (word: string) => any;
|
||||
isLoading: boolean;
|
||||
word?: string | null;
|
||||
}) => {
|
||||
const [searchText, setSearchText] = useState<string>(props.word ?? "");
|
||||
|
||||
useEffect(() => {
|
||||
if (!isEmptyString(searchText)) {
|
||||
props.handleSearch(searchText);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleInputSearchText = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setSearchText(event.target.value);
|
||||
};
|
||||
|
||||
const handleEnterKeySearch = (event: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key === "Go" || event.key === "Enter") {
|
||||
props.handleSearch(searchText);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="my-10 flex">
|
||||
<Input
|
||||
className="my-auto py-0"
|
||||
onChange={handleInputSearchText}
|
||||
onKeyDown={handleEnterKeySearch}
|
||||
placeholder="Input the keyword"
|
||||
value={searchText}
|
||||
/>
|
||||
<Button className="mx-3 my-auto w-32" disabled={props.isLoading} onClick={() => props.handleSearch(searchText)}>
|
||||
{props.isLoading ? "Loading" : "Search"}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
41
components/search-page/SearchResultList.tsx
Normal file
41
components/search-page/SearchResultList.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { TSearchResultItem } from "@/types/docs.type";
|
||||
import { nanoid } from "nanoid";
|
||||
import Link from "next/link";
|
||||
|
||||
export const SearchResultList = (props: {
|
||||
searchResult: TSearchResultItem[];
|
||||
}) => {
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-col justify-center">
|
||||
<div className={"flex min-h-full flex-col content-font"}>
|
||||
{props.searchResult.map((item, index) => (
|
||||
<Link
|
||||
className={`border-t p-2 ${
|
||||
index === props.searchResult.length - 1 && "border-b"
|
||||
} flex flex-col hover:bg-gray-50 dark:hover:bg-gray-900`}
|
||||
href={`/blog/${item.id}`}
|
||||
key={nanoid()}
|
||||
target="_blank"
|
||||
>
|
||||
<div className="my-1">
|
||||
<div className="post-list-caption-font font-bold text-md capitalize">{item.title}</div>
|
||||
{item.summary && <div className="">{item.summary}</div>}
|
||||
</div>
|
||||
<div className="flex flex-wrap space-x-2">
|
||||
{item.tags?.map((tagitem) => (
|
||||
<div className="text-gray-500 text-sm dark:text-gray-400" key={nanoid()}>
|
||||
{tagitem}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="my-3 text-center text-gray-500 dark:text-gray-400">
|
||||
<p className="mx-auto text-sm">{"For search efficiency, only the first 20 results are displayed."}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
12
components/utils/PageTitle.tsx
Normal file
12
components/utils/PageTitle.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export const PageTitle = (props: {
|
||||
children?: React.ReactNode;
|
||||
classNames?: string;
|
||||
}) => {
|
||||
return (
|
||||
<h2 className={twMerge("caption-font my-5 flex select-none justify-center font-bold text-2xl", props.classNames)}>
|
||||
{props.children}
|
||||
</h2>
|
||||
);
|
||||
};
|
||||
63
components/utils/Pagination.tsx
Normal file
63
components/utils/Pagination.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { type ChangeEvent, type KeyboardEvent, useState } from "react";
|
||||
import { MdNavigateBefore, MdNavigateNext } from "react-icons/md";
|
||||
|
||||
export const Pagination = (props: {
|
||||
pageNumber: number;
|
||||
pageAmount: number;
|
||||
onGotoNextPage: (nextPage: number) => any;
|
||||
onGotoPrevPage: (prevPage: number) => any;
|
||||
onJumpToSpecPage: (pageNum: number) => any;
|
||||
}) => {
|
||||
const [pageNumberInput, setPageNumberInput] = useState<string>(props.pageNumber.toString());
|
||||
|
||||
const handleEnterKeyJump = (event: KeyboardEvent<HTMLInputElement>) => {
|
||||
setPageNumberInput(pageNumberInput.replace(/[^\d]/g, ""));
|
||||
if (Number.parseInt(pageNumberInput) > 0 && Number.parseInt(pageNumberInput) < props.pageAmount + 1) {
|
||||
(event.key === "Go" || event.key === "Enter") && props.onJumpToSpecPage(Number.parseInt(pageNumberInput));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputPageNumber = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setPageNumberInput(event.target.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="my-5 flex justify-between font-bold text-base rtl:flex-row-reverse">
|
||||
{props.pageNumber !== 1 && (
|
||||
<Button
|
||||
className="rounded-full"
|
||||
onClick={() => {
|
||||
setPageNumberInput((props.pageNumber - 1).toString());
|
||||
props.onGotoPrevPage(props.pageNumber - 1);
|
||||
}}
|
||||
>
|
||||
<MdNavigateBefore className="text-3xl" />
|
||||
</Button>
|
||||
)}
|
||||
<div className="my-auto flex justify-center font-bold">
|
||||
<Input
|
||||
className="mx-2 my-auto h-6 w-11"
|
||||
onChange={handleInputPageNumber}
|
||||
onKeyDown={handleEnterKeyJump}
|
||||
title="Type the specified page number and press Enter to jump."
|
||||
value={pageNumberInput}
|
||||
/>
|
||||
<div className="my-auto">{` / ${props.pageAmount}`}</div>
|
||||
</div>
|
||||
{props.pageNumber !== props.pageAmount && (
|
||||
<Button
|
||||
className="rounded-full"
|
||||
onClick={() => {
|
||||
setPageNumberInput((props.pageNumber + 1).toString());
|
||||
props.onGotoNextPage(props.pageNumber + 1);
|
||||
}}
|
||||
>
|
||||
<MdNavigateNext className="text-3xl" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -37,7 +37,7 @@ export const PostList = (props: { data: TPostListItem[] }) => {
|
||||
</div>
|
||||
{postItem.frontMatter.tags && (
|
||||
<div className="my-auto flex flex-wrap">
|
||||
{postItem.frontMatter.tags.map((tagName) => (
|
||||
{postItem.frontMatter.tags.map((tagName: string) => (
|
||||
<Badge
|
||||
className="my-1 mr-1 text-gray-600 dark:text-gray-300"
|
||||
key={`tags-${nanoid()}`}
|
||||
|
||||
Reference in New Issue
Block a user