2022.4.18
+路由布局结构修改为 React-Router 官方提供的 方案,改善 404 页面效果
+2022.4.13
陆续还原网易云、随机动漫音乐等 API 的说明页面,引入 PrismJS 实现代码高亮
网易云 API 增加别名字段,随机动漫音乐 API 增加缓存的字段(番名)
diff --git a/.env b/.env new file mode 100644 index 0000000..da03b7a --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +DB_NAME=paul_api_next +DB_USER=root +DB_PASS=233456 +DB_PORT=8889 +DB_LINK=localhost + +PAUL_SITENAME="保罗 API Next" diff --git a/midway.config.ts b/midway.config.ts index 9609c40..b54050e 100644 --- a/midway.config.ts +++ b/midway.config.ts @@ -14,5 +14,6 @@ export default defineConfig({ } ] }, + envPrefix: "PAUL_" }, }); diff --git a/src/components/Layout/Footer.tsx b/src/components/Layout/Footer.tsx index f207735..96e43bb 100644 --- a/src/components/Layout/Footer.tsx +++ b/src/components/Layout/Footer.tsx @@ -17,6 +17,7 @@ function Footer() {
+ 作者主页 使用约定 维护记录
diff --git a/src/components/Layout/FrontWrapper.tsx b/src/components/Layout/FrontWrapper.tsx new file mode 100644 index 0000000..3676f60 --- /dev/null +++ b/src/components/Layout/FrontWrapper.tsx @@ -0,0 +1,46 @@ +// React +import React, { useEffect, useLayoutEffect } from "react"; +import { useLocation } from "react-router-dom"; + + +// Components +import Aside from "@/components/Layout/Aside"; +import Footer from "@/components/Layout/Footer"; + + +// Interface +interface FrontWrapperProps { + title?: string + element: JSX.Element +} + + +// Components +function FrontWrapper(props: FrontWrapperProps) { + const location = useLocation(); + + useEffect(() => { + const name = import.meta.env.PAUL_SITENAME; + + if (props.title) { + document.title = `${props.title} - ${name}`; + } + else if (name) { + document.title = String(name); + } + }, []); + + useLayoutEffect(() => { + window.scrollTo({ top: 0, left: 0 }); + }, [location.pathname]); + + return ( + <> + + {props.element} + + > + ); +} + +export default FrontWrapper; diff --git a/src/images/404.webp b/src/images/404.webp new file mode 100644 index 0000000..65e7262 Binary files /dev/null and b/src/images/404.webp differ diff --git a/src/index.css b/src/index.css index 02cb0d4..1aeb5b6 100644 --- a/src/index.css +++ b/src/index.css @@ -317,7 +317,37 @@ footer .links a:last-child::after{ transform: rotate(45deg) translateX(50%); } -/* 4 - 附加 +/* 4 - 404 页面 +------------------------------ */ +.no-match{ + margin: auto; + max-width: 30em; + user-select: none; + text-align: center; + margin-bottom: 3em; +} + +.no-match h1{ + line-height: 1; + font-size: 3em; + font-weight: bold; +} + +.no-match p{ + opacity: .6; +} + +.no-match .board{ + margin: 0 auto; + color: #263555; + max-width: 20em; + padding: 2em 1em; + border-radius: 1em; + background-color: #bbf7ec; + border: 2px solid #263555; +} + +/* 5 - 附加 ------------------------------ */ .gt-meta{ margin-top: 0; diff --git a/src/index.tsx b/src/index.tsx index d36b9ea..d88599e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,10 +7,6 @@ import "./index.css"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; -// Components -import Aside from "./components/Layout/Aside"; -import Footer from "./components/Layout/Footer"; - // Routes import Home from "./pages/index"; @@ -24,22 +20,43 @@ import Bing from "./pages/bing"; import NoMatch from "./pages/404"; +// RouteWrapper +import FrontWrapper from "./components/Layout/FrontWrapper"; + + +// Components function App() { return (并没有这个页面啦
+路由布局结构修改为 React-Router 官方提供的 方案,改善 404 页面效果
+陆续还原网易云、随机动漫音乐等 API 的说明页面,引入 PrismJS 实现代码高亮
网易云 API 增加别名字段,随机动漫音乐 API 增加缓存的字段(番名)