Skip to content

Commit

Permalink
Merge pull request #2764 from tangly1024/release/4.7.3
Browse files Browse the repository at this point in the history
Release/4.7.3
  • Loading branch information
tangly1024 authored Sep 25, 2024
2 parents 4be65c2 + 4985b4a commit 03c116f
Show file tree
Hide file tree
Showing 52 changed files with 2,032 additions and 585 deletions.
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
NEXT_PUBLIC_VERSION=4.7.2
NEXT_PUBLIC_VERSION=4.7.3


# 可在此添加环境变量,去掉最左边的(# )注释即可
Expand Down
25 changes: 21 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@ module.exports = {
es2021: true,
node: true
},
extends: ['plugin:react/recommended', 'plugin:@next/next/recommended', 'standard', 'prettier'],
extends: [
'plugin:react/jsx-runtime',
'plugin:react/recommended',
'plugin:@next/next/recommended',
'standard',
'prettier',
'plugin:@typescript-eslint/recommended', // 添加 TypeScript 推荐规则
'plugin:@typescript-eslint/recommended-requiring-type-checking' // 添加需要类型检查的规则
],
parser: '@typescript-eslint/parser', // 使用 TypeScript 解析器
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 12,
sourceType: 'module'
sourceType: 'module',
project: './tsconfig.json' // 指定 tsconfig.json 的路径
},
plugins: ['react', 'react-hooks', 'prettier'],
plugins: [
'react',
'react-hooks',
'prettier',
'@typescript-eslint' // 添加 TypeScript 插件
],
settings: {
react: {
version: 'detect'
Expand All @@ -23,7 +38,9 @@ module.exports = {
'react/no-unknown-property': 'off', // <style jsx>
'react/prop-types': 'off',
'space-before-function-paren': 0,
'react-hooks/rules-of-hooks': 'error' // Checks rules of Hooks
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], // 确保未使用的变量报错
'@typescript-eslint/explicit-function-return-type': 'off' // 关闭强制函数返回类型声明
},
globals: {
React: true
Expand Down
5 changes: 3 additions & 2 deletions blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ const BLOG = {
'/[prefix]': 'LayoutSlug',
'/[prefix]/[slug]': 'LayoutSlug',
'/[prefix]/[slug]/[...suffix]': 'LayoutSlug',
'/signin': 'LayoutSignIn',
'/signup': 'LayoutSignUp'
'/auth/result': 'LayoutAuth',
'/sign-in/[[...index]]': 'LayoutSignIn',
'/sign-up/[[...index]]': 'LayoutSignUp'
},

CAN_COPY: process.env.NEXT_PUBLIC_CAN_COPY || true, // 是否允许复制页面内容 默认允许,如果设置为false、则全栈禁止复制内容。
Expand Down
28 changes: 19 additions & 9 deletions components/OpenWrite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { isBrowser, loadExternalResource } from '@/lib/utils'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
Expand All @@ -24,14 +25,10 @@ const OpenWrite = () => {
// 白名单
const whiteList = siteConfig('OPEN_WRITE_WHITE_LIST', '')

const loadOpenWrite = async () => {
const existWhite = existedWhiteList(router.asPath, whiteList)

// 如果当前页面在白名单中,则屏蔽加锁
if (existWhite) {
return
}
// 登录信息
const { isLoaded, isSignedIn } = useGlobal()

const loadOpenWrite = async () => {
try {
await loadExternalResource(
'https://readmore.openwrite.cn/js/readmore-2.0.js',
Expand Down Expand Up @@ -74,11 +71,24 @@ const OpenWrite = () => {
}
}
useEffect(() => {
const existWhite = existedWhiteList(router.asPath, whiteList)
// 白名单中,免检
if (existWhite) {
return
}
if (isSignedIn) {
// 用户已登录免检
console.log('用户已登录')
return
}

// 开发环境免检
if (process.env.NODE_ENV === 'development') {
console.log('开发环境:屏蔽OpenWrite')
return
}
if (isBrowser && blogId) {

if (isBrowser && blogId && !isSignedIn) {
toggleTocItems(true) // 禁止目录项的点击

// Check if the element with id 'read-more-wrap' already exists
Expand All @@ -89,7 +99,7 @@ const OpenWrite = () => {
loadOpenWrite()
}
}
})
}, [isLoaded, router])

// 启动一个监听器,当页面上存在#read-more-wrap对象时,所有的 a .notion-table-of-contents-item 对象都禁止点击

Expand Down
16 changes: 8 additions & 8 deletions components/SideBarDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const SideBarDrawer = ({
showOnPC = false
}) => {
const router = useRouter()

useEffect(() => {
const sideBarDrawerRouteListener = () => {
switchSideDrawerVisible(false)
Expand All @@ -38,33 +39,32 @@ const SideBarDrawer = ({
)

if (showStatus) {
sideBarDrawer?.classList.replace('-ml-96', 'ml-0')
sideBarDrawer?.classList.replace('translate-x-[-100%]', 'translate-x-0')
sideBarDrawerBackground?.classList.replace('hidden', 'block')
} else {
sideBarDrawer?.classList.replace('ml-0', '-ml-96')
sideBarDrawer?.classList.replace('translate-x-0', 'translate-x-[-100%]')
sideBarDrawerBackground?.classList.replace('block', 'hidden')
}
}

return (
<div
id='sidebar-wrapper'
className={` block ${showOnPC ? '' : 'lg:hidden'} top-0`}>
className={`block ${showOnPC ? '' : 'lg:hidden'} top-0`}>
<div
id='sidebar-drawer'
className={`${className} ${isOpen ? 'ml-0 w-96 visible' : '-ml-96 max-w-side invisible'} bg-white dark:bg-gray-900 flex flex-col duration-300 fixed h-full left-0 overflow-y-scroll scroll-hidden top-0 z-30`}>
className={`z-50 ${className} ${isOpen ? 'translate-x-0 opacity-100' : 'translate-x-[-100%] opacity-0'} transform transition-transform duration-300 ease-in-out bg-white dark:bg-gray-900 flex flex-col fixed h-full left-0 overflow-y-scroll top-0`}>
{children}
</div>

{/* 背景蒙版 */}
<div
id='sidebar-drawer-background'
onClick={() => {
switchSideDrawerVisible(false)
}}
className={`${isOpen ? 'block' : 'hidden'} animate__animated animate__fadeIn fixed top-0 duration-300 left-0 z-20 w-full h-full bg-black/70`}
onClick={() => switchSideDrawerVisible(false)}
className={`${isOpen ? 'block' : 'hidden'} fixed top-0 left-0 z-20 w-full h-full bg-black/70 transition-opacity duration-300`}
/>
</div>
)
}

export default SideBarDrawer
4 changes: 2 additions & 2 deletions components/ThemeSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ThemeSwitch = () => {
</Draggable>

<SideBarDrawer
className='p-10'
className='p-10 max-w-3xl 2xl:max-w-5xl'
isOpen={sideBarVisible}
showOnPC={true}
onClose={() => {
Expand Down Expand Up @@ -98,7 +98,7 @@ const ThemeSwitch = () => {
<div> Click below to switch the theme.</div>

{/* 陈列所有主题 */}
<div>
<div className='grid lg:grid-cols-2 gap-6'>
{THEMES?.map(t => {
return (
<div
Expand Down
5 changes: 5 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"jsx": "react",
"allowJs": true,
"checkJs": true,
"baseUrl": ".",
"paths": {
"@/*": ["./*"],
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
// console.warn('SiteConfig警告', key, error)
}

// 首先 配置最优先读取NOTION中的表格配置
// 配置最优先读取NOTION中的表格配置
let val = null
let siteInfo = null

Expand Down
16 changes: 15 additions & 1 deletion lib/global.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { APPEARANCE, LANG, NOTION_PAGE_ID, THEME } from '@/blog.config'
import {
THEMES,
getThemeConfig,
initDarkMode,
saveDarkModeToLocalStorage
} from '@/themes/theme'
import { APPEARANCE, LANG, NOTION_PAGE_ID, THEME } from 'blog.config'
import { useUser } from '@clerk/nextjs'
import { useRouter } from 'next/router'
import { createContext, useContext, useEffect, useState } from 'react'
import {
Expand All @@ -13,6 +14,10 @@ import {
redirectUserLang,
saveLangToLocalStorage
} from './lang'

/**
* 全局上下文
*/
const GlobalContext = createContext()

export function GlobalContextProvider(props) {
Expand All @@ -37,6 +42,12 @@ export function GlobalContextProvider(props) {
const [onLoading, setOnLoading] = useState(true) // 抓取文章数据
const router = useRouter()

// 登录验证相关
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
const { isLoaded, isSignedIn, user } = enableClerk
? useUser()
: { isLoaded: true, isSignedIn: false, user: false }

// 是否全屏
const fullWidth = post?.fullWidth ?? false

Expand Down Expand Up @@ -119,6 +130,9 @@ export function GlobalContextProvider(props) {
return (
<GlobalContext.Provider
value={{
isLoaded,
isSignedIn,
user,
fullWidth,
NOTION_CONFIG,
THEME_CONFIG,
Expand Down
5 changes: 4 additions & 1 deletion lib/lang/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default {
},
COMMON: {
THEME: 'Theme',
SIGN_IN: 'Sign In',
SIGN_OUT: 'Sign Out',
ARTICLE_LIST: 'Article List',
RECOMMEND_POSTS: 'Recommend Posts',
MORE: 'More',
Expand Down Expand Up @@ -66,7 +68,8 @@ export default {
MINUTE: 'min',
WORD_COUNT: 'Words',
READ_TIME: 'Read Time',
NEXT_POST: '下一篇'
NEXT_POST: 'Next',
PREV_POST: 'Prev'
},
PAGINATION: {
PREV: 'Prev',
Expand Down
5 changes: 4 additions & 1 deletion lib/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default {
},
COMMON: {
THEME: 'Theme',
SIGN_IN: '登录',
SIGN_OUT: '登出',
ARTICLE_LIST: '文章列表',
RECOMMEND_POSTS: '推荐文章',
MORE: '更多',
Expand Down Expand Up @@ -66,7 +68,8 @@ export default {
MINUTE: '分钟',
WORD_COUNT: '字数',
READ_TIME: '阅读时长',
NEXT_POST: '下一篇'
NEXT_POST: '下一篇',
PREV_POST: '上一篇'
},
PAGINATION: {
PREV: '上页',
Expand Down
4 changes: 3 additions & 1 deletion lib/lang/zh-HK.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export default {
ARTICLE_LOCK_TIPS: '文章已上鎖,請輸入訪問密碼',
SUBMIT: '提交',
POST_TIME: '发布于',
LAST_EDITED_TIME: '最后更新'
LAST_EDITED_TIME: '最后更新',
NEXT_POST: '下一篇',
PREV_POST: '上一篇'
},
PAGINATION: {
PREV: '上一頁',
Expand Down
4 changes: 3 additions & 1 deletion lib/lang/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export default {
ARTICLE_LOCK_TIPS: '文章已上鎖,請輸入訪問密碼',
SUBMIT: '提交',
POST_TIME: '发布于',
LAST_EDITED_TIME: '最后更新'
LAST_EDITED_TIME: '最后更新',
NEXT_POST: '下一篇',
PREV_POST: '上一篇'
},
PAGINATION: {
PREV: '上一頁',
Expand Down
Loading

0 comments on commit 03c116f

Please sign in to comment.