Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jun 28, 2024
2 parents 51838ab + b3e008a commit d9ad4da
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 67 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.6.0
NEXT_PUBLIC_VERSION=4.6.1


# 可在此添加环境变量,去掉最左边的(# )注释即可
Expand Down
20 changes: 11 additions & 9 deletions components/ThemeSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ const ThemeSwitch = () => {
<div
id='draggableBox'
style={{ left: '0px', top: '80vh' }}
className='fixed group hover:scale-105 transition-all space-y-2 overflow-hidden z-50 p-3 flex flex-col items-start dark:text-white bg-white dark:bg-black rounded-xl shadow-lg '>
className='fixed group flex flex-col items-start space-y-2 overflow-hidden z-50 p-3
dark:text-white bg-white dark:bg-black
rounded-xl shadow-lg hover:scale-105 hover:shadow-2xl '>
{/* 主题切换按钮 */}
<div className='text-sm flex items-center group-hover:w-32 transition-all duration-200'>
<div className='text-sm flex items-center group-hover:w-32 duration-200'>
<i className='fa-solid fa-palette w-5' />
<div className='w-0 group-hover:w-24 transition-all duration-200 overflow-hidden'>
<div className='w-0 group-hover:w-24 duration-200 overflow-hidden'>
<label htmlFor='themeSelect' className='sr-only'>
{locale.COMMON.THEME}
</label>
Expand All @@ -79,21 +81,21 @@ const ThemeSwitch = () => {
</div>

{/* 深色按钮 */}
<div className='text-sm flex items-center w-0 group-hover:w-32 transition-all duration-200'>
<div className='text-sm flex items-center w-0 group-hover:w-32 duration-200'>
<DarkModeButton />
<div
onClick={toggleDarkMode}
className='cursor-pointer w-0 group-hover:w-24 transition-all duration-200 overflow-hidden whitespace-nowrap pl-1 h-auto'>
className='cursor-pointer w-0 group-hover:w-24 duration-200 overflow-hidden whitespace-nowrap pl-1 h-auto'>
{isDarkMode ? locale.MENU.DARK_MODE : locale.MENU.LIGHT_MODE}
</div>
</div>

{/* 翻译按钮 */}
<div className='text-sm flex items-center group-hover:w-32 transition-all duration-200'>
<div className='text-sm flex items-center group-hover:w-32 duration-200'>
<i className='fa-solid fa-language w-5' />
<div className='w-0 group-hover:w-24 transition-all duration-200 overflow-hidden'>
<div className='w-0 group-hover:w-24 duration-200 overflow-hidden'>
<label htmlFor='langSelect' className='sr-only'>
选择语言:
Language Select
</label>
<select
id='langSelect'
Expand All @@ -118,7 +120,7 @@ const ThemeSwitch = () => {
<div
className={`${isLoading ? 'opacity-90 ' : 'opacity-0'}
w-screen h-screen glassmorphism bg-black text-white shadow-text flex justify-center items-center
transition-all fixed top-0 left-0 pointer-events-none duration-1000 z-50 shadow-inner`}>
fixed top-0 left-0 pointer-events-none duration-1000 z-50 shadow-inner`}>
<i className='text-3xl mr-5 fas fa-spinner animate-spin' />
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
let siteInfo = null

if (global) {
val = global.NOTION_CONFIG?.[key]
siteInfo = global.siteInfo
val = global.NOTION_CONFIG?.[key] || global.THEME_CONFIG?.[key]
}

if (!val) {
Expand Down
14 changes: 14 additions & 0 deletions lib/global.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
THEMES,
getThemeConfig,
initDarkMode,
saveDarkModeToLocalStorage
} from '@/themes/theme'
Expand Down Expand Up @@ -29,11 +30,14 @@ export function GlobalContextProvider(props) {
tagOptions,
NOTION_CONFIG
} = props

const [lang, updateLang] = useState(NOTION_CONFIG?.LANG || LANG) // 默认语言
const [locale, updateLocale] = useState(
generateLocaleDict(NOTION_CONFIG?.LANG || LANG)
) // 默认语言
const [theme, setTheme] = useState(NOTION_CONFIG?.THEME || THEME) // 默认博客主题
const [THEME_CONFIG, SET_THEME_CONFIG] = useState(null) // 主题配置

const defaultDarkMode = NOTION_CONFIG?.APPEARANCE || APPEARANCE
const [isDarkMode, updateDarkMode] = useState(defaultDarkMode === 'dark') // 默认深色模式
const [onLoading, setOnLoading] = useState(false) // 抓取文章数据
Expand All @@ -54,6 +58,12 @@ export function GlobalContextProvider(props) {
return newTheme
}

// 抓取主题配置
const updateThemeConfig = async theme => {
const config = await getThemeConfig(theme)
SET_THEME_CONFIG(config)
}

// 切换深色模式
const toggleDarkMode = () => {
const newStatus = !isDarkMode
Expand Down Expand Up @@ -99,6 +109,9 @@ export function GlobalContextProvider(props) {
setOnLoading(false)
}

const currentTheme = router?.query?.theme || theme
updateThemeConfig(currentTheme)

router.events.on('routeChangeStart', handleStart)
router.events.on('routeChangeError', handleStop)
router.events.on('routeChangeComplete', handleStop)
Expand All @@ -114,6 +127,7 @@ export function GlobalContextProvider(props) {
value={{
fullWidth,
NOTION_CONFIG,
THEME_CONFIG,
toggleDarkMode,
onLoading,
setOnLoading,
Expand Down
6 changes: 3 additions & 3 deletions lib/notion/getPageProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
}

// http or https 开头的视为外链
if (checkStartWithHttp(properties?.slug)) {
if (checkStartWithHttp(properties?.href)) {
properties.href = properties?.slug
properties.target = '_blank'
} else {
Expand All @@ -197,16 +197,16 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
if (
!properties?.href?.endsWith('.html') &&
!properties?.href?.startsWith('http') &&
properties?.href !== '' &&
properties?.href !== '#' &&
properties?.href !== '/'
) {
properties.href += '.html'
}
}

// 相对路径转绝对路径:url左侧拼接 /
convertUrlStartWithOneSlash(properties?.href)
properties.href = convertUrlStartWithOneSlash(properties?.href)
}

// 如果跳转链接是多语言,则在新窗口打开
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notion-next",
"version": "4.6.0",
"version": "4.6.1",
"homepage": "https://github.com/tangly1024/NotionNext.git",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions public/js/sakura.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,11 @@ a.avatar-wrapper {
writing-mode: vertical-rl; /* 竖向排列从右向左 */
text-orientation: upright; /* 文字方向正常 */
}

/* Chatbase 在移动端禁止遮挡 */
@media (max-width: 700px) {
button#chatbase-bubble-button {
margin-bottom: 42px;
margin-right: 20px;
}
}
94 changes: 94 additions & 0 deletions themes/example/components/Catalog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
import { useCallback, useEffect, useRef, useState } from 'react'

/**
* 目录导航组件
* @param toc
* @returns {JSX.Element}
* @constructor
*/
const Catalog = ({ toc }) => {
// 监听滚动事件
useEffect(() => {
window.addEventListener('scroll', actionSectionScrollSpy)
actionSectionScrollSpy()
return () => {
window.removeEventListener('scroll', actionSectionScrollSpy)
}
}, [])

// 目录自动滚动
const tRef = useRef(null)
const tocIds = []

// 同步选中目录事件
const [activeSection, setActiveSection] = useState(null)
const throttleMs = 200
const actionSectionScrollSpy = useCallback(
throttle(() => {
const sections = document.getElementsByClassName('notion-h')
let prevBBox = null
let currentSectionId = activeSection
for (let i = 0; i < sections.length; ++i) {
const section = sections[i]
if (!section || !(section instanceof Element)) continue
if (!currentSectionId) {
currentSectionId = section.getAttribute('data-id')
}
const bbox = section.getBoundingClientRect()
const prevHeight = prevBBox ? bbox.top - prevBBox.bottom : 0
const offset = Math.max(150, prevHeight / 4)
// GetBoundingClientRect returns values relative to viewport
if (bbox.top - offset < 0) {
currentSectionId = section.getAttribute('data-id')
prevBBox = bbox
continue
}
// No need to continue loop, if last element has been detected
break
}
setActiveSection(currentSectionId)
const index = tocIds.indexOf(currentSectionId) || 0
tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
}, throttleMs)
)

// 无目录就直接返回空
if (!toc || toc.length < 1) {
return <></>
}

return (
<div className='px-3'>
<div
className='overflow-y-auto max-h-96 overscroll-none scroll-hidden'
ref={tRef}>
<nav className='h-full text-black dark:text-gray-300'>
{toc.map(tocItem => {
const id = uuidToId(tocItem.id)
tocIds.push(id)
return (
<a
key={id}
href={`#${id}`}
className={`notion-table-of-contents-item duration-300 transform font-light
notion-table-of-contents-item-indent-level-${tocItem.indentLevel} `}>
<span
style={{
display: 'inline-block',
marginLeft: tocItem.indentLevel * 16
}}
className={`truncate ${activeSection === id ? ' font-bold text-red-400 underline' : ''}`}>
{tocItem.text}
</span>
</a>
)
})}
</nav>
</div>
</div>
)
}

export default Catalog
11 changes: 11 additions & 0 deletions themes/example/components/SideBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import dynamic from 'next/dynamic'
import Link from 'next/link'
import CONFIG from '../config'
import Announcement from './Announcement'
import Catalog from './Catalog'
const ExampleRecentComments = dynamic(
() => import('./RecentCommentListForExample')
)
Expand Down Expand Up @@ -32,6 +33,16 @@ export const SideBar = props => {

return (
<>
{/* 目录 */}
{post?.toc && post?.toc.length > 2 && (
<aside className='w-full rounded shadow overflow-hidden mb-6 pb-4'>
<h3 className='text-sm bg-gray-100 text-gray-700 dark:bg-hexo-black-gray dark:text-gray-200 py-3 px-4 dark:border-hexo-black-gray border-b'>
{locale.COMMON.TABLE_OF_CONTENTS}
</h3>
<Catalog toc={post?.toc} />
</aside>
)}

{/* 分类 */}
<aside className='w-full rounded shadow overflow-hidden mb-6'>
<h3 className='text-sm bg-gray-100 text-gray-700 dark:bg-hexo-black-gray dark:text-gray-200 py-3 px-4 dark:border-hexo-black-gray border-b'>
Expand Down
2 changes: 1 addition & 1 deletion themes/fukasawa/components/AsideLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function AsideLeft(props) {
}
}, [isCollapsed])

const isReverse = siteConfig('LAYOUT_SIDEBAR_REVERSE')
const position = useMemo(() => {
const isReverse = JSON.parse(siteConfig('LAYOUT_SIDEBAR_REVERSE'))
if (isCollapsed) {
if (isReverse) {
return 'right-2'
Expand Down
10 changes: 6 additions & 4 deletions themes/fukasawa/components/MenuItemDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export const MenuItemDrop = ({ link }) => {

return (
<li
onMouseOver={() => changeShow(true)}
onMouseOver={() => {
changeShow(true)
}}
onMouseOut={() => changeShow(false)}
className='relative py-1 duration-500 justify-between text-gray-500 dark:text-gray-300 hover:text-black hover:underline cursor-pointer flex flex-nowrap items-center '>
className='relative py-1 mb-1.5 duration-500 justify-between text-gray-500 dark:text-gray-300 hover:text-black hover:underline cursor-pointer flex flex-nowrap items-center '>
{!hasSubMenu && (
<Link
href={link?.href}
Expand All @@ -33,7 +35,7 @@ export const MenuItemDrop = ({ link }) => {
{hasSubMenu && (
<div className='text-right'>
<i
className={`px-2 fas fa-chevron-right duration-500 transition-all ${show ? ' rotate-180' : ''}`}></i>
className={`px-2 fas fa-chevron-left duration-500 transition-all ${show ? ' rotate-180' : ''}`}></i>
</div>
)}
</div>
Expand All @@ -42,7 +44,7 @@ export const MenuItemDrop = ({ link }) => {
{/* 子菜单 */}
{hasSubMenu && (
<ul
className={`${show ? 'visible opacity-100 left-52' : 'invisible opacity-0 left-40'} z-20 py-1 absolute right-0 top-0 w-full border-gray-100 bg-white dark:bg-black dark:border-gray-800 transition-all duration-300 drop-shadow-lg `}>
className={`${show ? 'visible opacity-100 left-72' : 'invisible opacity-0 left-80'} z-20 p-2 absolute right-0 top-0 w-full border-gray-100 bg-white dark:bg-black dark:border-gray-800 transition-all duration-300 drop-shadow-lg `}>
{link?.subMenus?.map((sLink, index) => {
return (
<li key={index}>
Expand Down
5 changes: 0 additions & 5 deletions themes/fukasawa/components/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ export const MenuList = props => {
name: locale.NAV.ARCHIVE,
href: '/archive',
show: siteConfig('FUKASAWA_MENU_ARCHIVE', null, CONFIG)
},
{
name: locale.NAV.SEARCH,
href: '/search',
show: siteConfig('FUKASAWA_MENU_SEARCH', null, CONFIG)
}
]

Expand Down
2 changes: 0 additions & 2 deletions themes/fukasawa/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ const CONFIG = {
FUKASAWA_MENU_CATEGORY: true, // 显示分类
FUKASAWA_MENU_TAG: true, // 显示标签
FUKASAWA_MENU_ARCHIVE: true, // 显示归档
FUKASAWA_MENU_SEARCH: false, // 显示搜索

FUKASAWA_SIDEBAR_COLLAPSE_BUTTON: true, // 侧边栏折叠按钮
FUKASAWA_SIDEBAR_COLLAPSE_SATUS_DEFAULT: false, // 侧边栏默认折叠收起
FUKASAWA_SIDEBAR_COLLAPSE_ON_SCROLL: false // 侧边栏滚动时折叠 仅文章阅读页有效

}
export default CONFIG
2 changes: 1 addition & 1 deletion themes/gitbook/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const LayoutBase = props => {

<div
id='theme-gitbook'
className={`${siteConfig('FONT_STYLE')} scroll-smooth bg-white dark:bg-hexo-black-gray w-full h-full min-h-screen justify-center dark:text-gray-300`}>
className={`${siteConfig('FONT_STYLE')} pb-16 md:pb-0 scroll-smooth bg-white dark:bg-hexo-black-gray w-full h-full min-h-screen justify-center dark:text-gray-300`}>
<AlgoliaSearchModal cRef={searchModal} {...props} />

{/* 顶部导航栏 */}
Expand Down
Loading

0 comments on commit d9ad4da

Please sign in to comment.