fix: 修复 eslint 报错

This commit is contained in:
LooseLi
2025-05-27 10:52:32 +08:00
parent d9bbf58aa6
commit e631507ce2
12 changed files with 52 additions and 43 deletions

View File

@@ -8,7 +8,7 @@ import { useEffect } from 'react'
* https://michalsnik.github.io/aos/
*/
export default function AOSAnimation() {
const initAOS = async () => {
const initAOS = () => {
Promise.all([
loadExternalResource('/js/aos.js', 'js'),
loadExternalResource('/css/aos.css', 'css')

View File

@@ -14,16 +14,19 @@ export default function AdBlockDetect() {
const wwadsCns = document.getElementsByClassName('wwads-cn')
if (wwadsCns && wwadsCns.length > 0) {
for (const wwadsCn of wwadsCns) {
wwadsCn.insertAdjacentHTML('beforeend', "<style>.wwads-horizontal,.wwads-vertical{background-color:#f4f8fa;padding:5px;min-height:120px;margin-top:20px;box-sizing:border-box;border-radius:3px;font-family:sans-serif;display:flex;min-width:150px;position:relative;overflow:hidden;}.wwads-horizontal{flex-wrap:wrap;justify-content:center}.wwads-vertical{flex-direction:column;align-items:center;padding-bottom:32px}.wwads-horizontal a,.wwads-vertical a{text-decoration:none}.wwads-horizontal .wwads-img,.wwads-vertical .wwads-img{margin:5px}.wwads-horizontal .wwads-content,.wwads-vertical .wwads-content{margin:5px}.wwads-horizontal .wwads-content{flex:130px}.wwads-vertical .wwads-content{margin-top:10px}.wwads-horizontal .wwads-text,.wwads-content .wwads-text{font-size:14px;line-height:1.4;color:#0e1011;-webkit-font-smoothing:antialiased}.wwads-horizontal .wwads-poweredby,.wwads-vertical .wwads-poweredby{display:block;font-size:11px;color:#a6b7bf;margin-top:1em}.wwads-vertical .wwads-poweredby{position:absolute;left:10px;bottom:10px}.wwads-horizontal .wwads-poweredby span,.wwads-vertical .wwads-poweredby span{transition:all 0.2s ease-in-out;margin-left:-1em}.wwads-horizontal .wwads-poweredby span:first-child,.wwads-vertical .wwads-poweredby span:first-child{opacity:0}.wwads-horizontal:hover .wwads-poweredby span,.wwads-vertical:hover .wwads-poweredby span{opacity:1;margin-left:0}.wwads-horizontal .wwads-hide,.wwads-vertical .wwads-hide{position:absolute;right:-23px;bottom:-23px;width:46px;height:46px;border-radius:23px;transition:all 0.3s ease-in-out;cursor:pointer;}.wwads-horizontal .wwads-hide:hover,.wwads-vertical .wwads-hide:hover{background:rgb(0 0 0 /0.05)}.wwads-horizontal .wwads-hide svg,.wwads-vertical .wwads-hide svg{position:absolute;left:10px;top:10px;fill:#a6b7bf}.wwads-horizontal .wwads-hide:hover svg,.wwads-vertical .wwads-hide:hover svg{fill:#3E4546}</style><a href='https://wwads.cn/page/whitelist-wwads' class='wwads-img' target='_blank' rel='nofollow'><img src='https://creatives-1301677708.file.myqcloud.com/images/placeholder/wwads-friendly-ads.png' width='130'></a><div class='wwads-content'><a href='https://wwads.cn/page/whitelist-wwads' class='wwads-text' target='_blank' rel='nofollow'>为了本站的长期运营,请将我们的网站加入广告拦截器的白名单,感谢您的支持!</a><a href='https://wwads.cn/page/end-user-privacy' class='wwads-poweredby' title='万维广告 让广告更优雅,且有用' target='_blank'><span>万维</span><span>广告</span></a></div><a class='wwads-hide' onclick='parentNode.remove()' title='隐藏广告'><svg xmlns='http://www.w3.org/2000/svg' width='6' height='7'><path d='M.879.672L3 2.793 5.121.672a.5.5 0 11.707.707L3.708 3.5l2.12 2.121a.5.5 0 11-.707.707l-2.12-2.12-2.122 2.12a.5.5 0 11-.707-.707l2.121-2.12L.172 1.378A.5.5 0 01.879.672z'></path></svg></a>")
wwadsCn.insertAdjacentHTML(
'beforeend',
"<style>.wwads-horizontal,.wwads-vertical{background-color:#f4f8fa;padding:5px;min-height:120px;margin-top:20px;box-sizing:border-box;border-radius:3px;font-family:sans-serif;display:flex;min-width:150px;position:relative;overflow:hidden;}.wwads-horizontal{flex-wrap:wrap;justify-content:center}.wwads-vertical{flex-direction:column;align-items:center;padding-bottom:32px}.wwads-horizontal a,.wwads-vertical a{text-decoration:none}.wwads-horizontal .wwads-img,.wwads-vertical .wwads-img{margin:5px}.wwads-horizontal .wwads-content,.wwads-vertical .wwads-content{margin:5px}.wwads-horizontal .wwads-content{flex:130px}.wwads-vertical .wwads-content{margin-top:10px}.wwads-horizontal .wwads-text,.wwads-content .wwads-text{font-size:14px;line-height:1.4;color:#0e1011;-webkit-font-smoothing:antialiased}.wwads-horizontal .wwads-poweredby,.wwads-vertical .wwads-poweredby{display:block;font-size:11px;color:#a6b7bf;margin-top:1em}.wwads-vertical .wwads-poweredby{position:absolute;left:10px;bottom:10px}.wwads-horizontal .wwads-poweredby span,.wwads-vertical .wwads-poweredby span{transition:all 0.2s ease-in-out;margin-left:-1em}.wwads-horizontal .wwads-poweredby span:first-child,.wwads-vertical .wwads-poweredby span:first-child{opacity:0}.wwads-horizontal:hover .wwads-poweredby span,.wwads-vertical:hover .wwads-poweredby span{opacity:1;margin-left:0}.wwads-horizontal .wwads-hide,.wwads-vertical .wwads-hide{position:absolute;right:-23px;bottom:-23px;width:46px;height:46px;border-radius:23px;transition:all 0.3s ease-in-out;cursor:pointer;}.wwads-horizontal .wwads-hide:hover,.wwads-vertical .wwads-hide:hover{background:rgb(0 0 0 /0.05)}.wwads-horizontal .wwads-hide svg,.wwads-vertical .wwads-hide svg{position:absolute;left:10px;top:10px;fill:#a6b7bf}.wwads-horizontal .wwads-hide:hover svg,.wwads-vertical .wwads-hide:hover svg{fill:#3E4546}</style><a href='https://wwads.cn/page/whitelist-wwads' class='wwads-img' target='_blank' rel='nofollow'><img src='https://creatives-1301677708.file.myqcloud.com/images/placeholder/wwads-friendly-ads.png' width='130'></a><div class='wwads-content'><a href='https://wwads.cn/page/whitelist-wwads' class='wwads-text' target='_blank' rel='nofollow'>为了本站的长期运营,请将我们的网站加入广告拦截器的白名单,感谢您的支持!</a><a href='https://wwads.cn/page/end-user-privacy' class='wwads-poweredby' title='万维广告 让广告更优雅,且有用' target='_blank'><span>万维</span><span>广告</span></a></div><a class='wwads-hide' onclick='parentNode.remove()' title='隐藏广告'><svg xmlns='http://www.w3.org/2000/svg' width='6' height='7'><path d='M.879.672L3 2.793 5.121.672a.5.5 0 11.707.707L3.708 3.5l2.12 2.121a.5.5 0 11-.707.707l-2.12-2.12-2.122 2.12a.5.5 0 11-.707-.707l2.121-2.12L.172 1.378A.5.5 0 01.879.672z'></path></svg></a>"
)
}
}
};
}
// check document ready
function docReady(t) {
document.readyState === 'complete' ||
document.readyState === 'interactive'
? setTimeout(t, 1)
? setTimeout(() => t(), 1)
: document.addEventListener('DOMContentLoaded', t)
}

View File

@@ -13,7 +13,6 @@ import WebWhiz from './Webwhiz'
import { useGlobal } from '@/lib/global'
import IconFont from './IconFont'
/**
* 各种插件脚本
* @param {*} props
@@ -22,7 +21,7 @@ import IconFont from './IconFont'
const ExternalPlugin = props => {
// 读取自Notion的配置
const { NOTION_CONFIG } = props
const {lang} = useGlobal()
const { lang } = useGlobal()
const DISABLE_PLUGIN = siteConfig('DISABLE_PLUGIN', null, NOTION_CONFIG)
const THEME_SWITCH = siteConfig('THEME_SWITCH', null, NOTION_CONFIG)
const DEBUG = siteConfig('DEBUG', null, NOTION_CONFIG)
@@ -172,7 +171,7 @@ const ExternalPlugin = props => {
setTimeout(() => {
// 映射url
convertInnerUrl({ allPages:props?.allNavPages, lang:lang })
convertInnerUrl({ allPages: props?.allNavPages, lang: lang })
}, 500)
}, [router])
@@ -474,7 +473,7 @@ const DifyChatbot = dynamic(() => import('@/components/DifyChatbot'), {
})
const Analytics = dynamic(
() =>
import('@vercel/analytics/react').then(async m => {
import('@vercel/analytics/react').then(m => {
return m.Analytics
}),
{ ssr: false }

View File

@@ -16,7 +16,7 @@ const Fireworks = () => {
useEffect(() => {
// 异步加载
async function loadFireworks() {
function loadFireworks() {
loadExternalResource(
'https://cdnjs.snrat.com/ajax/libs/animejs/3.2.1/anime.min.js',
'js'

View File

@@ -60,7 +60,7 @@ function getNodesWithAdsByGoogleClass(node) {
* 初始化谷歌广告
* @returns
*/
export const initGoogleAdsense = async ADSENSE_GOOGLE_ID => {
export const initGoogleAdsense = ADSENSE_GOOGLE_ID => {
console.log('Load Adsense')
loadExternalResource(
`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ADSENSE_GOOGLE_ID}`,

View File

@@ -12,7 +12,9 @@ const Lenis = () => {
useEffect(() => {
// 异步加载
async function loadLenis() {
loadExternalResource('/js/lenis.js', 'js').then(() => {
try {
await loadExternalResource('/js/lenis.js', 'js')
// console.log('Lenis', window.Lenis)
if (!window.Lenis) {
console.error('Lenis not loaded')
@@ -23,14 +25,14 @@ const Lenis = () => {
// 创建 Lenis 实例
const lenis = new Lenis({
duration: 1.2,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
easing: t => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
direction: 'vertical', // vertical, horizontal
gestureDirection: 'vertical', // vertical, horizontal, both
smooth: true,
mouseMultiplier: 1,
smoothTouch: false,
touchMultiplier: 2,
infinite: false,
infinite: false
})
// 存储实例到 ref
@@ -48,7 +50,9 @@ const Lenis = () => {
}
requestAnimationFrame(raf)
})
} catch (error) {
console.error('Failed to load Lenis:', error)
}
}
loadLenis()

View File

@@ -228,7 +228,7 @@ function getMediumZoomMargin() {
// 代码
const Code = dynamic(
() =>
import('react-notion-x/build/third-party/code').then(async m => {
import('react-notion-x/build/third-party/code').then(m => {
return m.Code
}),
{ ssr: false }

View File

@@ -160,8 +160,8 @@ const renderCollapseCode = (codeCollapse, codeCollapseExpandDefault) => {
/**
* 将mermaid语言 渲染成图片
*/
const renderMermaid = async(mermaidCDN) => {
const observer = new MutationObserver(async mutationsList => {
const renderMermaid = mermaidCDN => {
const observer = new MutationObserver(mutationsList => {
for (const m of mutationsList) {
if (m.target.className === 'notion-code language-mermaid') {
const chart = m.target.querySelector('code').textContent

View File

@@ -4,21 +4,19 @@ import React from 'react'
* 下拉单选框
*/
class Select extends React.Component {
constructor (props) {
super(props)
this.handleChange = this.handleChange.bind(this)
}
handleChange (event) {
handleChange = event => {
const { onChange } = this.props
onChange(event.target.value)
}
render () {
render() {
return (
<div className='py-1 space-x-3'>
<label className='text-gray-500'>{this.props.label}</label>
<select value={this.props.value} onChange={this.handleChange} className='border p-1 rounded cursor-pointer'>
<select
value={this.props.value}
onChange={this.handleChange}
className='border p-1 rounded cursor-pointer'>
{this.props.options?.map(o => (
<option key={o.value} value={o.value}>
{o.text}

View File

@@ -6,10 +6,10 @@ const cacheInvalidSeconds = 1000000000 * 1000
// 文件名
const jsonFile = path.resolve('./data.json')
export async function getCache (key) {
const exist = await fs.existsSync(jsonFile)
export function getCache(key) {
const exist = fs.existsSync(jsonFile)
if (!exist) return null
const data = await fs.readFileSync(jsonFile)
const data = fs.readFileSync(jsonFile)
let json = null
if (!data) return null
try {
@@ -19,7 +19,9 @@ export async function getCache (key) {
return null
}
// 缓存超过有效期就作废
const cacheValidTime = new Date(parseInt(json[key + '_expire_time']) + cacheInvalidSeconds)
const cacheValidTime = new Date(
parseInt(json[key + '_expire_time']) + cacheInvalidSeconds
)
const currentTime = new Date()
if (!cacheValidTime || cacheValidTime < currentTime) {
return null
@@ -33,17 +35,17 @@ export async function getCache (key) {
* @param data
* @returns {Promise<null>}
*/
export async function setCache (key, data) {
const exist = await fs.existsSync(jsonFile)
const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {}
export function setCache(key, data) {
const exist = fs.existsSync(jsonFile)
const json = exist ? JSON.parse(fs.readFileSync(jsonFile)) : {}
json[key] = data
json[key + '_expire_time'] = new Date().getTime()
fs.writeFileSync(jsonFile, JSON.stringify(json))
}
export async function delCache (key) {
const exist = await fs.existsSync(jsonFile)
const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {}
export function delCache(key) {
const exist = fs.existsSync(jsonFile)
const json = exist ? JSON.parse(fs.readFileSync(jsonFile)) : {}
delete json.key
json[key + '_expire_time'] = new Date().getTime()
fs.writeFileSync(jsonFile, JSON.stringify(json))
@@ -52,7 +54,7 @@ export async function delCache (key) {
/**
* 清理缓存
*/
export async function cleanCache() {
export function cleanCache() {
const json = {}
fs.writeFileSync(jsonFile, JSON.stringify(json))
}

View File

@@ -13,7 +13,7 @@ export async function getCache(key) {
const data = await redisClient.get(key)
return data ? JSON.parse(data) : null
} catch (e) {
console.error('redisClient读取失败 ' + e)
console.error(`redisClient读取失败 ${String(e)}`)
}
}
@@ -26,7 +26,7 @@ export async function setCache(key, data, customCacheTime) {
customCacheTime || cacheTime
)
} catch (e) {
console.error('redisClient写入失败 ' + e)
console.error(`redisClient写入失败 ${String(e)}`)
}
}
@@ -34,7 +34,7 @@ export async function delCache(key) {
try {
await redisClient.del(key)
} catch (e) {
console.error('redisClient删除失败 ' + e)
console.error(`redisClient删除失败 ${String(e)}`)
}
}

View File

@@ -39,8 +39,9 @@ export function GlobalContextProvider(props) {
// 登录验证相关
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
const clerkUser = useUser()
const { isLoaded, isSignedIn, user } = enableClerk
? useUser()
? clerkUser
: { isLoaded: true, isSignedIn: false, user: false }
// 是否全屏
@@ -99,9 +100,11 @@ export function GlobalContextProvider(props) {
useEffect(() => {
const handleStart = url => {
const { theme } = router.query
if (theme && !url.includes(`theme=${theme}`)) {
const newUrl = `${url}${url.includes('?') ? '&' : '?'}theme=${theme}`
const themeValue = router.query.theme
const themeStr = Array.isArray(themeValue) ? themeValue[0] : themeValue
if (themeStr && !url.includes(`theme=${themeStr}`)) {
const newUrl = `${url}${url.includes('?') ? '&' : '?'}theme=${themeStr}`
router.push(newUrl)
}
if (!onLoading) {