Merge branch 'main' into fix/algolia/no-slug-error

This commit is contained in:
tangly1024
2025-07-27 21:24:10 +08:00
committed by GitHub
352 changed files with 1800 additions and 1519 deletions

View File

@@ -3,7 +3,7 @@ import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import algoliasearch from 'algoliasearch'
import throttle from 'lodash/throttle'
import Link from 'next/link'
import SmartLink from '@/components/SmartLink'
import { useRouter } from 'next/router'
import {
Fragment,
@@ -357,7 +357,7 @@ function TagGroups() {
<div id='tags-group' className='dark:border-gray-700 space-y-2'>
{firstTenTags?.map((tag, index) => {
return (
<Link
<SmartLink
passHref
key={index}
href={`/tag/${encodeURIComponent(tag.name)}`}
@@ -373,7 +373,7 @@ function TagGroups() {
<></>
)}
</div>
</Link>
</SmartLink>
)
})}
</div>

View File

@@ -2,7 +2,7 @@ import useWindowSize from '@/hooks/useWindowSize'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { THEMES, saveDarkModeToLocalStorage } from '@/themes/theme'
import Link from 'next/link'
import SmartLink from '@/components/SmartLink'
import { useRouter } from 'next/router'
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
@@ -198,23 +198,23 @@ export default function CustomContextMenu(props) {
)}
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU_CATEGORY && (
<Link
<SmartLink
href='/category'
title={locale.MENU.CATEGORY}
className='w-full px-2 h-10 flex justify-start items-center flex-nowrap cursor-pointer hover:bg-blue-600 hover:text-white rounded-lg duration-200 transition-all'>
<i className='fa-solid fa-square-minus mr-2' />
<div className='whitespace-nowrap'>{locale.MENU.CATEGORY}</div>
</Link>
</SmartLink>
)}
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU_TAG && (
<Link
<SmartLink
href='/tag'
title={locale.MENU.TAGS}
className='w-full px-2 h-10 flex justify-start items-center flex-nowrap cursor-pointer hover:bg-blue-600 hover:text-white rounded-lg duration-200 transition-all'>
<i className='fa-solid fa-tag mr-2' />
<div className='whitespace-nowrap'>{locale.MENU.TAGS}</div>
</Link>
</SmartLink>
)}
</div>

View File

@@ -64,7 +64,7 @@ const Player = () => {
<link
rel='stylesheet'
type='text/css'
href='https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/aplayer/1.10.1/APlayer.min.css'
href='https://cdn.jsdelivr.net/npm/aplayer@1.10.0/dist/APlayer.min.css'
/>
{meting ? (
<meting-js

52
components/SmartLink.js Normal file
View File

@@ -0,0 +1,52 @@
import Link from 'next/link'
import { siteConfig } from '@/lib/config'
// 过滤 <a> 标签不能识别的 props
const filterDOMProps = props => {
const { passHref, legacyBehavior, ...rest } = props
return rest
}
const SmartLink = ({ href, children, ...rest }) => {
const LINK = siteConfig('LINK')
// 获取 URL 字符串用于判断是否是外链
let urlString = ''
if (typeof href === 'string') {
urlString = href
} else if (
typeof href === 'object' &&
href !== null &&
typeof href.pathname === 'string'
) {
urlString = href.pathname
}
const isExternal = urlString.startsWith('http') && !urlString.startsWith(LINK)
if (isExternal) {
// 对于外部链接,必须是 string 类型
const externalUrl =
typeof href === 'string' ? href : new URL(href.pathname, LINK).toString()
return (
<a
href={externalUrl}
target='_blank'
rel='noopener noreferrer'
{...filterDOMProps(rest)}>
{children}
</a>
)
}
// 内部链接(可为对象形式)
return (
<Link href={href} {...rest}>
{children}
</Link>
)
}
export default SmartLink

View File

@@ -1,5 +1,5 @@
import { siteConfig } from '@/lib/config'
import Link from 'next/link'
import SmartLink from '@/components/SmartLink'
import { useRouter } from 'next/router'
/**
* 跳转仪表盘的按钮
@@ -24,7 +24,7 @@ export default function DashboardButton({ className }) {
<button
type='button'
className={`${className || ''} text-white bg-gray-800 hover:bg-gray-900 hover:ring-4 hover:ring-gray-300 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2 me-2 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:border-gray-700`}>
<Link href='/dashboard'>仪表盘</Link>
<SmartLink href='/dashboard'>仪表盘</SmartLink>
</button>
)
}

View File

@@ -1,7 +1,7 @@
import LazyImage from '@/components/LazyImage'
import { useGlobal } from '@/lib/global'
import formatDate from '@/lib/utils/formatDate'
import Link from 'next/link'
import SmartLink from '@/components/SmartLink'
import DashboardSignOutButton from './DashboardSignOutButton'
/**
@@ -25,11 +25,11 @@ export default function DashboardHeader() {
<div class='font-medium dark:text-white'>
<div className='flex items-center gap-x-2'>
<span>{user?.fullName}</span>
<Link href='/dashboard/membership'>
<SmartLink href='/dashboard/membership'>
<span class='bg-gray-100 text-gray-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-gray-300'>
普通用户
</span>
</Link>
</SmartLink>
</div>
<div className='text-sm text-gray-500 gap-x-2 flex dark:text-gray-400'>
<span>{user?.username}</span>

View File

@@ -1,4 +1,4 @@
import Link from 'next/link'
import SmartLink from '@/components/SmartLink'
/**
* 联盟行销
@@ -140,11 +140,11 @@ export default function DashboardItemAffliate() {
for='remember'
className='ms-2 text-sm font-medium text-gray-900 dark:text-gray-300'>
我以阅读并同意{' '}
<Link
<SmartLink
href='/terms-of-use'
className='text-blue-600 hover:underline dark:text-blue-500'>
服务协议
</Link>
</SmartLink>
.
</label>
</div>

View File

@@ -1,4 +1,4 @@
import Link from 'next/link'
import SmartLink from '@/components/SmartLink'
/**
* 仪表盘菜单
@@ -43,12 +43,12 @@ export default function DashboardMenuList() {
className={`rounded-lg cursor-pointer block ${
isActive ? 'bg-blue-100 text-blue-600' : 'hover:bg-gray-100'
}`}>
<Link
<SmartLink
href={item.href}
className='block py-2 px-4 w-full items-center justify-center'>
<i className={`${item.icon} w-6 mr-2`}></i>
<span className='whitespace-nowrap'>{item.title}</span>
</Link>
</SmartLink>
</li>
)
})}