diff --git a/packages/website/.dockerignore b/packages/website/.dockerignore index c5500558b..261454abd 100644 --- a/packages/website/.dockerignore +++ b/packages/website/.dockerignore @@ -1,3 +1,4 @@ +__tests__/ Dockerfile .dockerignore node_modules diff --git a/packages/website/__tests__/capitalize.spec.ts b/packages/website/__tests__/capitalize.spec.ts new file mode 100644 index 000000000..7d9226e6e --- /dev/null +++ b/packages/website/__tests__/capitalize.spec.ts @@ -0,0 +1,12 @@ +import { describe, it, expect } from "vitest"; +import { capitalize } from "../utils/capitalize"; + +describe("capitalize", () => { + it("Should capitalize content", () => { + expect(capitalize("hello")).toBe("Hello"); + }); + + it("Should not throw", () => { + expect(capitalize("")).toBe(""); + }); +}); diff --git a/packages/website/components/ImageBoxFuture/index.tsx b/packages/website/components/ImageBoxFuture/index.tsx index 2a97903ed..28b1ee747 100644 --- a/packages/website/components/ImageBoxFuture/index.tsx +++ b/packages/website/components/ImageBoxFuture/index.tsx @@ -2,7 +2,7 @@ import "react-photo-view/dist/react-photo-view.css"; import { PhotoView } from "react-photo-view"; import { useState } from "react"; import Image from "next/image"; -import { isIp } from "../../utils/isIp"; +import { isIP } from "../../utils/isIp"; export const errorImg = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAwqADAAQAAAABAAAAwwAAAAD9b/HnAAAHlklEQVR4Ae3dP3PTWBSGcbGzM6GCKqlIBRV0dHRJFarQ0eUT8LH4BnRU0NHR0UEFVdIlFRV7TzRksomPY8uykTk/zewQfKw/9znv4yvJynLv4uLiV2dBoDiBf4qP3/ARuCRABEFAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghgg0Aj8i0JO4OzsrPv69Wv+hi2qPHr0qNvf39+iI97soRIh4f3z58/u7du3SXX7Xt7Z2enevHmzfQe+oSN2apSAPj09TSrb+XKI/f379+08+A0cNRE2ANkupk+ACNPvkSPcAAEibACyXUyfABGm3yNHuAECRNgAZLuYPgEirKlHu7u7XdyytGwHAd8jjNyng4OD7vnz51dbPT8/7z58+NB9+/bt6jU/TI+AGWHEnrx48eJ/EsSmHzx40L18+fLyzxF3ZVMjEyDCiEDjMYZZS5wiPXnyZFbJaxMhQIQRGzHvWR7XC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EKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiEC/wGgKKC4YMA4TAAAAABJRU5ErkJggg=="; @@ -35,7 +35,7 @@ export default function (props: { ); } else { - if (isIp(window.location.hostname) && !ipError) { + if (isIP(window.location.hostname) && !ipError) { return ( (decodeTheme("auto")); + const [theme, setTheme] = useState(getTheme("auto")); const handleClose = () => { console.log("关闭或刷新页面"); localStorage.removeItem("saidHello"); diff --git a/packages/website/components/MarkdownTocBar/tools.ts b/packages/website/components/MarkdownTocBar/tools.ts index 5682c7504..e2bb0ca86 100644 --- a/packages/website/components/MarkdownTocBar/tools.ts +++ b/packages/website/components/MarkdownTocBar/tools.ts @@ -4,6 +4,7 @@ export interface NavItem { listNo: string; text: string; } + export const washMarkdownContent = (source: string) => { if (!source) return ""; return ( @@ -19,6 +20,7 @@ export const washMarkdownContent = (source: string) => { .trim() + "\n" ); }; + export const parseNavStructure = (source: string): NavItem[] => { const contentWithoutCode = washMarkdownContent(source); const pattOfTitle = /#+\s(.+)\n/g; diff --git a/packages/website/components/SocialIcon/index.tsx b/packages/website/components/SocialIcon/index.tsx index c2e6c1fce..256be308e 100644 --- a/packages/website/components/SocialIcon/index.tsx +++ b/packages/website/components/SocialIcon/index.tsx @@ -2,7 +2,7 @@ import { useContext, useMemo, useState } from "react"; import { SocialItem } from "../../api/getAllData"; import { getIcon } from "../../utils/getIcon"; import { Popover, ArrowContainer } from "react-tiny-popover"; -import { topUpper } from "../../utils/TopUpper"; +import { capitalize } from "../../utils/capitalize"; import ImageBoxFuture from "../ImageBoxFuture"; import { ThemeContext } from "../../utils/themeContext"; @@ -99,7 +99,7 @@ export default function (props: { item: SocialItem }) { {getIcon(props.item.type, iconSize)} - {topUpper(props.item.type)} + {capitalize(props.item.type)} @@ -119,7 +119,7 @@ export default function (props: { item: SocialItem }) { {getIcon(props.item.type, iconSize)} - {topUpper(props.item.type)} + {capitalize(props.item.type)} ); diff --git a/packages/website/components/ThemeButton/core.tsx b/packages/website/components/ThemeButton/core.tsx index 904186ddd..3faf72ccd 100644 --- a/packages/website/components/ThemeButton/core.tsx +++ b/packages/website/components/ThemeButton/core.tsx @@ -1,5 +1,5 @@ import { useContext, useLayoutEffect, useRef } from "react"; -import { applyTheme, decodeTheme, initTheme } from "../../utils/theme"; +import { applyTheme, getTheme, initTheme } from "../../utils/theme"; import { ThemeContext } from "../../utils/themeContext"; export default function (props: { defaultTheme: "auto" | "dark" | "light" }) { @@ -11,7 +11,7 @@ export default function (props: { defaultTheme: "auto" | "dark" | "light" }) { clearTimer(); localStorage.setItem("theme", newTheme); // 设置真实的主题,然后把真实的主题搞到 state 里。 - const realTheme = decodeTheme(newTheme); + const realTheme = getTheme(newTheme); applyTheme(realTheme, "setTheme", true); setState(realTheme); if (realTheme.includes("auto")) { @@ -25,7 +25,7 @@ export default function (props: { defaultTheme: "auto" | "dark" | "light" }) { const setTimer = () => { clearTimer(); currentTimer.timer = setInterval(() => { - const realTheme = decodeTheme("auto"); + const realTheme = getTheme("auto"); applyTheme(realTheme, "autoThemeTimer", true); }, 10000); }; diff --git a/packages/website/package.json b/packages/website/package.json index 96bdd4889..2dc7f559e 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -1,10 +1,11 @@ { "private": true, "scripts": { - "dev": "cross-env NODE_ENV=development next dev -p 3001 --hostname 0.0.0.0", + "anlysis": "cross-env ANALYZE=true next build", "build": "next build", - "start": "next start", - "anlysis": "cross-env ANALYZE=true next build" + "dev": "cross-env NODE_ENV=development next dev -p 3001 --hostname 0.0.0.0", + "test": "vitest", + "start": "next start" }, "dependencies": { "@next/bundle-analyzer": "^12.2.5", @@ -51,6 +52,7 @@ "cross-env": "^7.0.3", "postcss": "^8.4.14", "tailwindcss": "^3.1.2", - "typescript": "4.7.2" + "typescript": "4.7.2", + "vitest": "0.29.2" } } diff --git a/packages/website/pages/_document.tsx b/packages/website/pages/_document.tsx index 02276a06e..06518f590 100644 --- a/packages/website/pages/_document.tsx +++ b/packages/website/pages/_document.tsx @@ -1,10 +1,10 @@ import { Head, Html, Main, NextScript } from "next/document"; import Script from "next/script"; -import { decodeTheme, initTheme } from "../utils/theme"; +import { getTheme, initTheme } from "../utils/theme"; export default function Document() { return ( - +