Leo 3 лет назад
Родитель
Сommit
cd9be755d9
8 измененных файлов с 51 добавлено и 59 удалено
  1. 1 1
      libs/config.ts
  2. 1 3
      pages/_app.tsx
  3. 1 3
      pages/index.tsx
  4. 5 22
      pages/novel/[slug]/[chapter].tsx
  5. 34 19
      pages/novel/[slug]/index.tsx
  6. 1 3
      pages/novels/[genre].tsx
  7. 1 1
      styles/globals.scss
  8. 7 7
      types/http.d.ts

+ 1 - 1
libs/config.ts

@@ -1,3 +1,3 @@
-export const isServer = typeof window === undefined;
+export const isServer = typeof window === "undefined";
 export const API_HOST = "https://novels.yergoo.com";
 export const API_HOST = "https://novels.yergoo.com";
 export const GA_TRACKING_ID = "G-T6QZWX1BQ2";
 export const GA_TRACKING_ID = "G-T6QZWX1BQ2";

+ 1 - 3
pages/_app.tsx

@@ -67,9 +67,7 @@ const MyApp = ({ Component, pageProps }: AppPropsWithLayout) => {
 MyApp.getInitialProps = async function (context: AppContext) {
 MyApp.getInitialProps = async function (context: AppContext) {
   App.getInitialProps(context);
   App.getInitialProps(context);
 
 
-  const { data } = await fetch("https://novels.yergoo.com/api/genre/list").then(
-    (res) => res.json()
-  );
+  const { data } = await fetch("/api/genre/list").then((res) => res.json());
 
 
   return {
   return {
     pageProps: { genre: data },
     pageProps: { genre: data },

+ 1 - 3
pages/index.tsx

@@ -23,9 +23,7 @@ const Home = () => {
 };
 };
 
 
 export async function getServerSideProps() {
 export async function getServerSideProps() {
-  const data = await fetch(`https://novels.yergoo.com/api/list`).then((res) =>
-    res.json()
-  );
+  const data = await fetch(`/api/list`).then((res) => res.json());
 
 
   return {
   return {
     props: {
     props: {

+ 5 - 22
pages/novel/[slug]/[chapter].tsx

@@ -5,37 +5,22 @@ import { GetServerSideProps } from "next";
 import { ReactElement, useEffect, useState } from "react";
 import { ReactElement, useEffect, useState } from "react";
 
 
 import { get } from "../../../utils/http";
 import { get } from "../../../utils/http";
-// import useGet from "../../../utils/hooks/useGet";
+import useGet from "../../../utils/hooks/useGet";
 import Toc from "../../../components/novel/Toc";
 import Toc from "../../../components/novel/Toc";
 import Toolbar from "../../../components/novel/Toolbar";
 import Toolbar from "../../../components/novel/Toolbar";
 import Settings from "../../../components/novel/Settings";
 import Settings from "../../../components/novel/Settings";
 
 
 import type { NextPageWithLayout } from "../../_app";
 import type { NextPageWithLayout } from "../../_app";
-// import type { ChapterData } from "../../../types/http";
+import type { ChapterData } from "../../../types/http";
 
 
 import styles from "../../../styles/chapter.module.scss";
 import styles from "../../../styles/chapter.module.scss";
-import useSWR from "swr";
-
-interface ChapterData {
-  chapter: string;
-  content: string;
-  errmsg: string;
-  errno: number;
-  next: string;
-  pre: string;
-  title: string;
-}
 
 
 const Chapter: NextPageWithLayout = () => {
 const Chapter: NextPageWithLayout = () => {
   const { query } = useRouter();
   const { query } = useRouter();
 
 
-  const { data: chapterData = null } = useSWR<ChapterData>(
-    `/api/novel/chapter/${query.slug}/${query.chapter}`,
-    (url) => fetch(url).then((res) => res.json())
+  const { data: { data: chapterData } = { data: null } } = useGet<ChapterData>(
+    `/api/novel/chapter/${query.slug}/${query.chapter}`
   );
   );
-  // const { data: { data: chapterData } = { data: null } } = useGet<ChapterData>(
-  //   `/api/novel/chapter/${query.slug}/${query.chapter}`
-  // );
 
 
   const [open, setOpen] = useState(false);
   const [open, setOpen] = useState(false);
   const [menu, setMenu] = useState("");
   const [menu, setMenu] = useState("");
@@ -221,9 +206,7 @@ export const getServerSideProps: GetServerSideProps<
   }
   }
   const { slug, chapter } = context.params;
   const { slug, chapter } = context.params;
   const [chapterData] = await Promise.all([
   const [chapterData] = await Promise.all([
-    get<ChapterData>(
-      `https://novels.yergoo.com/api/novel/chapter/${slug}/${chapter}`
-    ),
+    get<ChapterData>(`/api/novel/chapter/${slug}/${chapter}`),
   ]);
   ]);
 
 
   return {
   return {

+ 34 - 19
pages/novel/[slug]/index.tsx

@@ -46,9 +46,16 @@ const Novel: NextPage<NovelPageProps> = (props) => {
                   Home
                   Home
                 </Link>
                 </Link>
               </li>
               </li>
-              <li>
-                <a>{detail.genre}</a>
-              </li>
+              {detail.genres && detail.genres.length > 0 ? (
+                <li>
+                  <Link
+                    title={detail.genres[0].name}
+                    href={`/novels/${detail.genres[0].uri}`}
+                  >
+                    {detail.genres[0].name}
+                  </Link>
+                </li>
+              ) : null}
               <li>{detail.name}</li>
               <li>{detail.name}</li>
             </ul>
             </ul>
           </div>
           </div>
@@ -65,24 +72,29 @@ const Novel: NextPage<NovelPageProps> = (props) => {
                 <small>Completed</small>
                 <small>Completed</small>
               </h1>
               </h1>
               <h2>
               <h2>
-                <a title="Fantasy" href="">
-                  <svg>
-                    <use xlinkHref="/icons.svg#paper"></use>
-                  </svg>
-                  <span>{detail.genre}</span>
-                </a>
+                {detail.genres && detail.genres.length > 0 ? (
+                  <Link
+                    title={detail.genres[0].name}
+                    href={`/novels/${detail.genres[0].uri}`}
+                  >
+                    <svg>
+                      <use xlinkHref="/icons.svg#paper"></use>
+                    </svg>
+                    <span>{detail.genres[0].name}</span>
+                  </Link>
+                ) : null}
                 <strong>
                 <strong>
                   <svg>
                   <svg>
                     <use xlinkHref="/icons.svg#chapter"></use>
                     <use xlinkHref="/icons.svg#chapter"></use>
                   </svg>
                   </svg>
-                  <span>0 Chapters</span>
+                  <span>{chapters.chapters.length} Chapters</span>
                 </strong>
                 </strong>
-                <strong>
+                {/* <strong>
                   <svg>
                   <svg>
                     <use xlinkHref="/icons.svg#eye"></use>
                     <use xlinkHref="/icons.svg#eye"></use>
                   </svg>
                   </svg>
                   <span>0 Views</span>
                   <span>0 Views</span>
-                </strong>
+                </strong> */}
               </h2>
               </h2>
               <div className={styles["btns"]}>
               <div className={styles["btns"]}>
                 <Link
                 <Link
@@ -114,9 +126,14 @@ const Novel: NextPage<NovelPageProps> = (props) => {
         <div className={clsx({ hidden: tab !== "about" })}>
         <div className={clsx({ hidden: tab !== "about" })}>
           <h2 className="sub-title">Tags</h2>
           <h2 className="sub-title">Tags</h2>
           <div className="tags">
           <div className="tags">
-            {detail.genre.split(",").map((item) => (
-              <Link href="" className="tag" key={item}>
-                {item}
+            {detail.genres.map((item) => (
+              <Link
+                title={item.name}
+                href={`/novels/${item.uri}`}
+                className="tag"
+                key={item.uri}
+              >
+                {item.name}
               </Link>
               </Link>
             ))}
             ))}
           </div>
           </div>
@@ -160,10 +177,8 @@ export const getServerSideProps: GetServerSideProps<
   }
   }
   const { slug } = context.params;
   const { slug } = context.params;
   const [detail, chapters] = await Promise.all([
   const [detail, chapters] = await Promise.all([
-    get<Detail>(`https://novels.yergoo.com/api/novel/${slug}`),
-    get<ChapterListData>(
-      `https://novels.yergoo.com/api/novel/${slug}/chapters`
-    ),
+    get<Detail>(`/api/novel/${slug}`),
+    get<ChapterListData>(`/api/novel/${slug}/chapters`),
   ]);
   ]);
 
 
   return {
   return {

+ 1 - 3
pages/novels/[genre].tsx

@@ -64,9 +64,7 @@ export const getServerSideProps: GetServerSideProps<
   { genre: string }
   { genre: string }
 > = async ({ params }) => {
 > = async ({ params }) => {
   const key = params?.genre ? `/api/genre/${params.genre}` : `/api/list`;
   const key = params?.genre ? `/api/genre/${params.genre}` : `/api/list`;
-  const data = await fetch(`https://novels.yergoo.com${key}`).then((res) =>
-    res.json()
-  );
+  const data = await fetch(key).then((res) => res.json());
 
 
   return {
   return {
     props: {
     props: {

+ 1 - 1
styles/globals.scss

@@ -126,7 +126,7 @@
 }
 }
 .header {
 .header {
   // @apply sticky border-b py-2 shadow bg-paper-alpha backdrop-blur z-40 top-0;
   // @apply sticky border-b py-2 shadow bg-paper-alpha backdrop-blur z-40 top-0;
-  @apply py-4 sticky top-0 z-40 w-full backdrop-blur flex-none  border-b border-slate-900/10 dark:border-slate-50/[0.06] bg-white/60  dark:bg-slate-900/75;
+  @apply py-3 sticky top-0 z-40 w-full backdrop-blur flex-none  border-b border-slate-900/10 dark:border-slate-50/[0.06] bg-white/60  dark:bg-slate-900/75;
 
 
   .container {
   .container {
     @apply flex justify-between items-center overflow-visible;
     @apply flex justify-between items-center overflow-visible;

+ 7 - 7
types/http.d.ts

@@ -4,6 +4,12 @@ export interface ResData<T> {
   errno: number;
   errno: number;
 }
 }
 
 
+export interface GenreItem {
+  id: number;
+  name: string;
+  uri: string;
+}
+
 export interface Detail {
 export interface Detail {
   id: number;
   id: number;
   img: string;
   img: string;
@@ -12,7 +18,7 @@ export interface Detail {
   uri: string;
   uri: string;
   author: string;
   author: string;
   desc: string;
   desc: string;
-  genre: string;
+  genres: GenreItem[];
   host: string;
   host: string;
   status: 0;
   status: 0;
   source: string;
   source: string;
@@ -55,9 +61,3 @@ export interface ChapterData {
   pre: string;
   pre: string;
   title: string;
   title: string;
 }
 }
-
-export interface GenreItem {
-  id: number;
-  name: string;
-  uri: string;
-}