Skip to content

Commit

Permalink
doc: 增加几篇文章
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghao1993 committed Sep 4, 2024
1 parent f99e35b commit 6ecc66a
Show file tree
Hide file tree
Showing 21 changed files with 3,256 additions and 159 deletions.
3 changes: 2 additions & 1 deletion app/api/blog/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function POST(request: Request) {
views_count: 1,
},
});

return responseHandler(res);
} else {
const updateRes = await prisma.post.update({
Expand All @@ -28,10 +29,10 @@ export async function POST(request: Request) {
views_count: res.views_count + 1,
},
});

return responseHandler(updateRes);
}
} catch (e) {
console.log(e);
return responseHandler(
null,
BusinessCode.normal,
Expand Down
4 changes: 2 additions & 2 deletions components/Article/ArticleItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function ArticleItem(data: { articleInfo: Post }) {
<Link
key={item}
href={`blog/category/${item}`}
className="px-2 rounded-lg bg-primary-500 text-white"
className="px-2 mr-1 rounded-lg bg-primary-500 text-white"
>
{item}
</Link>
Expand All @@ -47,7 +47,7 @@ export default function ArticleItem(data: { articleInfo: Post }) {
<Link
key={item}
href={`/blog/tag/${item}`}
className="px-2 rounded-lg bg-primary-500 text-white"
className="px-2 mr-1 rounded-lg bg-primary-500 text-white"
>
{item}
</Link>
Expand Down
4 changes: 2 additions & 2 deletions components/Icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function SignIn(props: { color: string }) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1.2em"
height="1.2em"
width="1.4em"
height="1.4em"
viewBox="0 0 24 24"
>
<rect width="24" fill="none" height="24" />
Expand Down
5 changes: 5 additions & 0 deletions components/Image/MdxImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import NextImage, { ImageProps } from "next/image";

const Image = ({ ...rest }: ImageProps) => <NextImage {...rest} />;

export default Image;
9 changes: 6 additions & 3 deletions components/LoginOutBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ export default function LoginInOut() {
<LoginModal open={visible} onClose={() => setVisible(false)} />

{status === "unauthenticated" ? (
<div onClick={() => setVisible(true)} className="login-icon">
<SignIn color={"rgba(0, 0, 0, 0.6)"} />
<div
onClick={() => setVisible(true)}
className="login-icon cursor-pointer"
>
<SignIn color={"rgba(0, 0, 0, 0.8)"} />
</div>
) : status === "authenticated" ? (
<Dropdown
Expand All @@ -62,7 +65,7 @@ export default function LoginInOut() {
shape={"circle"}
src={session?.user?.image}
alt="avatar"
className=" cursor-pointer "
className="cursor-pointer "
></Avatar>
</Dropdown>
) : (
Expand Down
14 changes: 6 additions & 8 deletions components/TOCInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ const TOCInline = ({
key={heading.value}
className={`${heading.depth >= indentDepth && "ml-6"}`}
>
<a
href={heading.url}
className="not-prose border-b border-primary-400 no-underline dark:border-primary-500"
>
<a href={heading.url} className="text-black dark:text-white">
{heading.value}
</a>
</li>
Expand All @@ -71,13 +68,14 @@ const TOCInline = ({
<>
{asDisclosure ? (
<details open>
<summary className="ml-6 pt-2 pb-2 text-xl font-bold">
Table of Contents
</summary>
<summary className="ml-6 pt-2 pb-2 text-xl font-bold">目录</summary>
<div className="ml-6">{tocList}</div>
</details>
) : (
tocList
<div>
<h1>目录</h1>
{tocList}
</div>
)}
</>
);
Expand Down
5 changes: 3 additions & 2 deletions components/blog/Categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import Link from "next/link";
const getCategory = () => {
return getAllCategory();
};

export default async function Category() {
const categories = getCategory();

return (
<div className="border rounded-lg">
<h2 className="px-4 py-2 border-b">分类</h2>
<div className="flex p-4 space-x-2">
<div className="flex p-4 flex-wrap">
{Object.keys(categories).map((item) => (
<Link
key={item}
className=" p-1 text-white flex bg-primary-400 item-center justify-center rounded-sm text-xs"
className="p-1 mb-2 mr-2 text-white flex bg-primary-400 item-center justify-center rounded-sm text-xs"
href={`/blog/category/${item}`}
>
<span>{item}</span>
Expand Down
13 changes: 13 additions & 0 deletions components/blog/Posts.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* @Author: wanghao1993 [email protected]
* @Date: 2024-09-04 13:57:31
* @LastEditors: wanghao1993 [email protected]
* @LastEditTime: 2024-09-04 17:24:33
* @FilePath: \blog-offical\components\blog\Posts.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
"use client";
import { ArticleType } from "@/types/article";
import ArticleItem from "@/components/Article/ArticleItem";
Expand All @@ -7,6 +15,11 @@ import { Post } from "contentlayer/generated";
export interface PostCardProps {
posts: Post[];
}
/**
* @description:
* @param {PostCardProps} param1
* @return {*}
*/
export default function PostsCard({ posts }: PostCardProps) {
const [mounted, setMounted] = useState(false);

Expand Down
10 changes: 9 additions & 1 deletion data/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/*
* @Author: wanghao1993 [email protected]
* @Date: 2024-09-04 13:57:31
* @LastEditors: wanghao1993 [email protected]
* @LastEditTime: 2024-09-04 17:08:15
* @FilePath: \blog-offical\data\utils\index.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { allPosts } from "contentlayer/generated";

export const getAllPostsMeta = () => {
// 文章日期排序,最新的在最前面
allPosts.sort((a, b) => {
return +new Date(a.date) < +new Date(a.date) ? 1 : -1;
return +new Date(a.date) < +new Date(b.date) ? 1 : -1;
});
return allPosts;
};
Expand Down
3 changes: 3 additions & 0 deletions lib/fetch_utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextResponse } from "next/server";
import prisma from "./pg";

export const StatusMsg = {
200: "Success",
Expand All @@ -22,5 +23,7 @@ export function responseHandler<T>(
code = BusinessCode.normal,
message = "success"
) {
prisma.$disconnect();

return NextResponse.json({ message, data, code }, { status });
}
1 change: 1 addition & 0 deletions lib/heading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export function remarkTocHeadings() {

export async function extractTocHeadings(markdown: string) {
const vfile = await remark().use(remarkTocHeadings).process(markdown);
console.log(vfile.data.toc);
return vfile.data.toc;
}
Loading

0 comments on commit 6ecc66a

Please sign in to comment.