Skip to content

Commit

Permalink
fix: 🐛 lighthouse
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuba-Ahhh committed Aug 24, 2024
1 parent fb1a149 commit 7429e96
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 23 deletions.
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ const nextConfig = {
images: {
unoptimized: true,
},
productionBrowserSourceMaps: true,
pageExtensions: ["js", "jsx", "md", "mdx", "ts", "tsx"],
webpack: (config, { isServer }) => {
webpack: (config, { dev, isServer }) => {
if (!isServer) {
config.externals = {
// 添加其他需要从 CDN 加载的依赖
};
if (!dev && !isServer) {
config.optimization.usedExports = true;
}
}
return config;
},
Expand Down
4 changes: 2 additions & 2 deletions src/app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use client";

import Image from "next/image";
import { useTheme } from "next-themes";
import { useThemeType } from "@/hooks";

export default function About() {
const { theme } = useTheme();
const { theme } = useThemeType();

return (
<div
Expand Down
16 changes: 10 additions & 6 deletions src/app/blog/[id]/ShareButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Link from "next/link";
import { FaTwitter, FaFacebook, FaLinkedin } from "react-icons/fa";

interface ShareButtonsProps {
Expand All @@ -8,30 +9,33 @@ interface ShareButtonsProps {
export default function ShareButtons({ url, title }: ShareButtonsProps) {
return (
<div className="flex space-x-4 mt-6">
<a
<Link
href={`https://twitter.com/intent/tweet?url=${url}&text=${title}`}
target="_blank"
rel="noopener noreferrer"
className="text-blue-400 hover:text-blue-500"
aria-label="在Twitter上分享"
>
<FaTwitter size={24} />
</a>
<a
</Link>
<Link
href={`https://www.facebook.com/sharer/sharer.php?u=${url}`}
target="_blank"
rel="noopener noreferrer"
className="text-blue-600 hover:text-blue-700"
aria-label="在Facebook上分享"
>
<FaFacebook size={24} />
</a>
<a
</Link>
<Link
href={`https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=${title}`}
target="_blank"
rel="noopener noreferrer"
className="text-blue-700 hover:text-blue-800"
aria-label="在LinkedIn上分享"
>
<FaLinkedin size={24} />
</a>
</Link>
</div>
);
}
8 changes: 8 additions & 0 deletions src/app/contact/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function PrivacyPage() {
return (
<div className="container mx-auto py-8">
<h1 className="text-2xl font-bold mb-4">隐私政策</h1>
<p>这里是您的隐私政策内容...</p>
</div>
);
}
8 changes: 8 additions & 0 deletions src/app/privacy/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function PrivacyPage() {
return (
<div className="container mx-auto py-8">
<h1 className="text-2xl font-bold mb-4">隐私政策</h1>
<p>这里是您的隐私政策内容...</p>
</div>
);
}
8 changes: 8 additions & 0 deletions src/app/terms/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function PrivacyPage() {
return (
<div className="container mx-auto py-8">
<h1 className="text-2xl font-bold mb-4">隐私政策</h1>
<p>这里是您的隐私政策内容...</p>
</div>
);
}
4 changes: 2 additions & 2 deletions src/components/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React, { useState, useCallback, useMemo } from "react";
import Image from "next/image";
import { throttle } from "lodash-es";
import { useTheme } from "next-themes";
import { useThemeType } from "@/hooks";

interface CopyButtonProps {
text: string;
Expand All @@ -13,7 +13,7 @@ interface CopyButtonProps {
const CopyButton: React.FC<CopyButtonProps> = ({ text, language }) => {
const [state, setState] = useState<"idle" | "copy" | "copied">("idle");
const [isHovered, setIsHovered] = useState(false);
const { theme } = useTheme();
const { theme } = useThemeType();

const throttledCopy = useMemo(
() =>
Expand Down
22 changes: 12 additions & 10 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import Link from "next/link";
import { Badge } from "@/components/ui/badge";

export default function Footer() {
const links = [
{ href: "/privacy", label: "隐私政策" },
{ href: "/terms", label: "使用条款" },
{ href: "/contact", label: "联系我们" },
];

return (
<footer className="border-t py-6 md:py-0">
<div className="container flex flex-col items-center justify-between gap-4 md:h-24 md:flex-row">
Expand All @@ -11,17 +17,13 @@ export default function Footer() {
</p>
</div>
<nav className="flex items-center space-x-4">
<Link href="/privacy" className="text-sm text-muted-foreground">
<Badge>隐私政策</Badge>
</Link>
<Link href="/terms" className="text-sm text-muted-foreground">
<Badge>使用条款</Badge>
</Link>
<Link href="/contact" className="text-sm text-muted-foreground">
<Badge>联系我们</Badge>
</Link>
{links.map((link) => (
<Link key={link.href} href={link.href} className="text-sm text-muted-foreground">
<Badge>{link.label}</Badge>
</Link>
))}
</nav>
</div>
</footer>
);
}
}
4 changes: 2 additions & 2 deletions src/components/ThemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { useState, useEffect } from "react";
import { useTheme } from "next-themes";
import { useThemeType } from "@/hooks";

const MoonIcon = () => (
<svg viewBox="0 0 1024 1024" className="w-5 h-5">
Expand All @@ -22,7 +22,7 @@ const SunIcon = () => (

function ThemeToggle() {
const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme();
const { theme, setTheme } = useThemeType();
const [userOverride, setUserOverride] = useState(false);

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./useThemeType";
10 changes: 10 additions & 0 deletions src/hooks/useThemeType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useTheme } from "next-themes";

export function useThemeType() {
const { theme, setTheme } = useTheme();

return {
theme,
setTheme,
};
}

0 comments on commit 7429e96

Please sign in to comment.