Skip to content

Commit

Permalink
优化:大改动
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYuYang01 committed Nov 28, 2024
1 parent 7cc2606 commit c087b68
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 52 deletions.
7 changes: 4 additions & 3 deletions src/api/project.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Request from "@/utils/request";
import { Theme, Web } from "@/types/app/project";

export const getWebDataAPI = () => Request<Web>("GET", "/project/web")
// 获取项目配置
export const getConfigDataAPI = <T>(type: string) => Request<T>("GET", `/config/list/${type}`)

export const getThemeDataAPI = () => Request<Theme>("GET", "/project/theme")
// 修改项目配置
export const editConfigDataAPI = (type: string, data: object) => Request<{ [string: string]: string }>("PATCH", `/config/${type}`, { data })
4 changes: 2 additions & 2 deletions src/app/api/rss/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Feed } from 'feed';
import { NextResponse } from 'next/server';

import { getArticlePagingAPI } from '@/api/article'
import { getWebDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'
import { getUserDataAPI } from '@/api/user'
import { Web } from '@/types/app/project';
import { User } from '@/types/app/user';
import { Article } from '@/types/app/article';

export async function GET() {
const { data: web } = await getWebDataAPI() || { data: {} as Web }
const { data: web } = await getConfigDataAPI<Web>("web") || { data: {} as Web }
const { data: user } = await getUserDataAPI() || { data: {} as User }
const { data: article } = await getArticlePagingAPI({ pagination: { page: 1, size: 8 } }) || { data: {} as Paginate<Article[]> }
const list = article?.result || []
Expand Down
4 changes: 2 additions & 2 deletions src/app/friend/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from "next/link";
import { Metadata } from "next";

import { getWebDataAPI } from "@/api/project";
import { getConfigDataAPI } from "@/api/project";
import { getWebListAPI, getWebTypeListAPI } from '@/api/web'
import { Web as WebLink, WebType } from "@/types/app/web";

Expand All @@ -20,7 +20,7 @@ export const metadata: Metadata = {

export default async () => {
const { data: user } = await getUserDataAPI() || { data: {} as User }
const { data: web } = await getWebDataAPI() || { data: {} as Web }
const { data: web } = await getConfigDataAPI<Web>("web") || { data: {} as Web }
const { data: linkList } = await getWebListAPI() || { data: [] as WebLink[] }
const { data: typeList } = await getWebTypeListAPI() || { data: [] as WebType[] }

Expand Down
4 changes: 2 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import RouteChangeHandler from '@/components/RouteChangeHandler'
import "@/styles/index.scss";
import "@/styles/tailwind.scss";

import { getWebDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'

import Tools from '@/components/Tools';
import NProgress from '@/components/NProgress';
import Confetti from '@/components/Confetti';
import { Web } from '@/types/app/project';

export default async function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
const { data } = await getWebDataAPI() || { data: {} as Web };
const { data } = await getConfigDataAPI<Web>("web") || { data: {} as Web };

// 尊重开源,禁止删除此版权信息!!!
console.log("🚀 欢迎使用 ThriveX 现代化博客管理系统")
Expand Down
6 changes: 3 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Container from "@/components/Container";
import ArticleLayout from "@/components/ArticleLayout";
import Sidebar from "@/components/Sidebar";

import { getThemeDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'
import { Theme } from "@/types/app/project";

interface Props {
Expand All @@ -14,11 +14,11 @@ interface Props {

export default async ({ searchParams }: Props) => {
const page = searchParams.page || 1;
const { data } = await getThemeDataAPI() || { data: {} as Theme }
const { data } = await getConfigDataAPI<Theme>("layout") || { data: {} as Theme }

return (
<>
<Swiper src={data?.swiperImage}>
<Swiper src={data?.swiper_image}>
{/* 星空背景组件 */}
<Starry />
{/* 打字机组件 */}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ArticleLayout/Classics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { GoTag } from "react-icons/go";
import Empty from '@/components/Empty';
import Show from '@/components/Show';

import { getThemeDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'
import { Theme } from '@/types/app/project';

interface ClassicsProps {
data: Paginate<Article[]>;
}

const Classics = async ({ data }: ClassicsProps) => {
const { data: theme } = await getThemeDataAPI() || { data: {} as Theme }
const { data: theme } = await getConfigDataAPI<Theme>("layout") || { data: {} as Theme }

const covers = JSON.parse(theme.covers || '[]')

Expand Down
12 changes: 6 additions & 6 deletions src/components/ArticleLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { getArticlePagingAPI } from '@/api/article'
import Pagination from "../Pagination"
import Classics from "./Classics"
import Waterfall from "./Waterfall"
import { getThemeDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'
import { Theme } from '@/types/app/project'
import { Article } from '@/types/app/article'

export default async ({ page }: { page: number }) => {
const { data: theme } = await getThemeDataAPI() || { data: {} as Theme }
const sidebar: string[] = JSON.parse(theme?.rightSidebar)
const { data: theme } = await getConfigDataAPI<Theme>("layout") || { data: {} as Theme }
const sidebar: string[] = JSON.parse(theme?.right_sidebar)

// 如果是瀑布流布局就显示28条数据,否则显示8条
const { data } = await getArticlePagingAPI({ pagination: { page, size: theme.isArticleLayout === "waterfall" ? 28 : 8 } }) || { data: {} as Paginate<Article[]> }
const { data } = await getArticlePagingAPI({ pagination: { page, size: theme.is_article_layout === "waterfall" ? 28 : 8 } }) || { data: {} as Paginate<Article[]> }
data.result = data.result?.filter(item => item.config.status !== "no_home")

return (
<>
<div className={`w-full md:w-[90%] ${sidebar.length ? 'lg:w-[68%] xl:w-[73%]' : 'w-full'} mx-auto transition-width`}>
{theme.isArticleLayout === "classics" && <Classics data={data} />}
{theme.isArticleLayout === "waterfall" && <Waterfall data={data} />}
{theme.is_article_layout === "classics" && <Classics data={data} />}
{theme.is_article_layout === "waterfall" && <Waterfall data={data} />}

<Pagination total={data?.pages} page={page} className="flex justify-center mt-5" />
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Image from 'next/image'
import Link from 'next/link';
import { Tooltip } from '@nextui-org/react';
import { getWebDataAPI } from '@/api/project';
import { getConfigDataAPI } from '@/api/project';
import { getUserDataAPI } from '@/api/user';
import { User } from '@/types/app/user';
import { Web } from '@/types/app/project';

export default async () => {
const { data: { avatar } } = await getUserDataAPI() || { data: {} as User }
const { data: { footer } } = await getWebDataAPI() || { data: {} as Web }
const { data: { footer } } = await getConfigDataAPI<Web>("web") || { data: {} as Web }

return (
<>
Expand All @@ -25,7 +25,7 @@ export default async () => {
<div className='py-4 border-t dark:border-black-a transition-colors'>
<Tooltip showArrow={true} content="一款免费、开源、年轻、高颜值的现代化博客管理系统">
<div className='flex justify-center items-center space-x-3'>
<Image src="https://bu.dusays.com/2024/11/17/6739adf188f64.png" width={30} height={30} alt='系统LOGO' />
<img src="https://bu.dusays.com/2024/11/17/6739adf188f64.png" width={30} height={30} alt='系统LOGO' />
<Link href="https://github.com/LiuYuYang01/ThriveX-Blog" target='_blank' className='hover:text-primary transition-colors'> 基于开源项目 ThriveX 构建</Link>
</div>
</Tooltip>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { BsFillMoonStarsFill, BsTextIndentLeft } from "react-icons/bs";

import { Cate } from '@/types/app/cate';
import { getCateListAPI } from '@/api/cate';
import { getWebDataAPI, getThemeDataAPI } from '@/api/project';
import { getConfigDataAPI } from '@/api/project';

import { useConfigStore } from '@/stores';
import { Theme, Web } from '@/types/app/project';
Expand All @@ -25,10 +25,10 @@ const Header = () => {

// 获取项目配置
const getConfigData = async () => {
const { data: web } = await getWebDataAPI() || { data: {} as Web };
const { data: web } = await getConfigDataAPI<Web>("web") || { data: {} as Web };
setWeb(web)

const { data: theme } = await getThemeDataAPI() || { data: {} as Theme };
const { data: theme } = await getConfigDataAPI<Theme>("layout") || { data: {} as Theme };
setTheme(theme)
}

Expand Down Expand Up @@ -90,8 +90,8 @@ const Header = () => {
<Link href="/" className="flex items-center p-5 text-[15px] transition-colors">
{
isDark
? <img src={theme?.darkLogo} alt="Logo" className='w-32 h-10 pr-5 hover:scale-90 transition-all' />
: <img src={isPathSty || isScrolled ? theme?.lightLogo : theme?.darkLogo} alt="Logo" className='w-32 h-10 pr-5 hover:scale-90 transition-all' />
? <img src={theme?.dark_logo} alt="Logo" className='w-32 h-10 pr-5 hover:scale-90 transition-all' />
: <img src={isPathSty || isScrolled ? theme?.light_logo : theme?.dark_logo} alt="Logo" className='w-32 h-10 pr-5 hover:scale-90 transition-all' />
}
</Link>

Expand Down
4 changes: 2 additions & 2 deletions src/components/Sidebar/Author/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import QQ from '@/assets/svg/socializing/QQ.svg'
import Weixin from '@/assets/svg/socializing/Weixin.svg'

import { getUserDataAPI } from '@/api/user';
import { getThemeDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'

import './index.scss';
import { User } from '@/types/app/user';

const Author = async () => {
const { data: user } = await getUserDataAPI() || { data: {} as User }
const { data: { social } } = await getThemeDataAPI() || { data: {} as Theme }
const { data: { social } } = await getConfigDataAPI<Theme>("layout") || { data: {} as Theme }

const socialList = JSON.parse(social)?.map((item: string) => JSON.parse(item))

Expand Down
6 changes: 3 additions & 3 deletions src/components/Sidebar/HotArticle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from 'next/link';
import Image from 'next/image';
import { getThemeDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'
import { getArticleListAPI } from '@/api/article';
import { IoIosArrowForward } from "react-icons/io";
import fire from '@/assets/svg/other/fire.svg';
Expand All @@ -9,10 +9,10 @@ import { Theme } from '@/types/app/project';
import { Article } from '@/types/app/article';

const RandomArticle = async () => {
const { data: theme } = await getThemeDataAPI() || { data: {} as Theme }
const { data: theme } = await getConfigDataAPI<Theme>("layout") || { data: {} as Theme }
const { data: article } = await getArticleListAPI() || { data: [] as Article[] }

const ids = JSON.parse(theme.recoArticle ? theme.recoArticle : '[]')
const ids = JSON.parse(theme.reco_article ? theme.reco_article : '[]')
const list = article.filter((item: Article) => ids.includes(item.id + ''))

return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Author from "./Author"
import HotArticle from "./HotArticle"
import RandomArticle from "./RandomArticle"
import Comment from "./Comment"
import { getThemeDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'
import { Theme } from "@/types/app/project"

export default async () => {
const { data: theme } = await getThemeDataAPI() || { data: {} as Theme }
const sidebar: string[] = JSON.parse(theme?.rightSidebar)
const { data: theme } = await getConfigDataAPI<Theme>("layout") || { data: {} as Theme }
const sidebar: string[] = JSON.parse(theme?.right_sidebar)

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Swiper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode } from 'react'
import Ripple from '@/components/Ripple'
import { getRandom } from '@/utils'
import { getThemeDataAPI } from '@/api/project'
import { getConfigDataAPI } from '@/api/project'
import { Theme } from '@/types/app/project'

interface Props {
Expand All @@ -11,7 +11,7 @@ interface Props {
}

export default async ({ src, isRipple = true, children }: Props) => {
const { data } = await getThemeDataAPI() || { data: {} as Theme }
const { data } = await getConfigDataAPI<Theme>("layout") || { data: {} as Theme }
const covers = JSON.parse(data.covers || '[]')

const sty = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Typed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default ({ className }: { className?: string }) => {
const el = useRef(null);

useEffect(() => {
if (theme.swiperText) {
const strings = JSON.parse(theme.swiperText || '{}')
if (theme.swiper_text) {
const strings = JSON.parse(theme.swiper_text || '{}')

const typed = new Typed(el.current, {
strings,
Expand Down
19 changes: 7 additions & 12 deletions src/types/app/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,23 @@ export interface Web {
title: string,
subhead: string,
favicon: string,
// lightLogo: string,
// darkLogo: string,
description: string,
keyword: string,
footer: string,
// font: string,
// social: string,
// covers: string
}

export type ArticleLayout = "classics" | "card" | "waterfall" | ""
export type RightSidebar = "author" | "hotArticle" | "randomArticle" | "newComments"

// 主题配置
export interface Theme {
isArticleLayout: string,
rightSidebar: string,
lightLogo: string,
darkLogo: string,
swiperImage: string,
swiperText: string,
recoArticle: string,
is_article_layout: string,
right_sidebar: string,
light_logo: string,
dark_logo: string,
swiper_image: string,
swiper_text: string,
reco_article: string,
social: string,
covers: string
}
Expand Down

0 comments on commit c087b68

Please sign in to comment.