Skip to content

Commit 9c37ad4

Browse files
authored
Merge branch 'tangly1024:main' into martini
2 parents 3658d68 + 4535dec commit 9c37ad4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+404
-212
lines changed

.env.local

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
2-
NEXT_PUBLIC_VERSION=4.6.0
2+
NEXT_PUBLIC_VERSION=4.6.1
33

44

55
# 可在此添加环境变量,去掉最左边的(# )注释即可

components/ThemeSwitch.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ const ThemeSwitch = () => {
5353
<div
5454
id='draggableBox'
5555
style={{ left: '0px', top: '80vh' }}
56-
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 '>
56+
className='fixed group flex flex-col items-start space-y-2 overflow-hidden z-50 p-3
57+
dark:text-white bg-white dark:bg-black
58+
rounded-xl shadow-lg hover:scale-105 hover:shadow-2xl '>
5759
{/* 主题切换按钮 */}
58-
<div className='text-sm flex items-center group-hover:w-32 transition-all duration-200'>
60+
<div className='text-sm flex items-center group-hover:w-32 duration-200'>
5961
<i className='fa-solid fa-palette w-5' />
60-
<div className='w-0 group-hover:w-24 transition-all duration-200 overflow-hidden'>
62+
<div className='w-0 group-hover:w-24 duration-200 overflow-hidden'>
6163
<label htmlFor='themeSelect' className='sr-only'>
6264
{locale.COMMON.THEME}
6365
</label>
@@ -79,21 +81,21 @@ const ThemeSwitch = () => {
7981
</div>
8082

8183
{/* 深色按钮 */}
82-
<div className='text-sm flex items-center w-0 group-hover:w-32 transition-all duration-200'>
84+
<div className='text-sm flex items-center w-0 group-hover:w-32 duration-200'>
8385
<DarkModeButton />
8486
<div
8587
onClick={toggleDarkMode}
86-
className='cursor-pointer w-0 group-hover:w-24 transition-all duration-200 overflow-hidden whitespace-nowrap pl-1 h-auto'>
88+
className='cursor-pointer w-0 group-hover:w-24 duration-200 overflow-hidden whitespace-nowrap pl-1 h-auto'>
8789
{isDarkMode ? locale.MENU.DARK_MODE : locale.MENU.LIGHT_MODE}
8890
</div>
8991
</div>
9092

9193
{/* 翻译按钮 */}
92-
<div className='text-sm flex items-center group-hover:w-32 transition-all duration-200'>
94+
<div className='text-sm flex items-center group-hover:w-32 duration-200'>
9395
<i className='fa-solid fa-language w-5' />
94-
<div className='w-0 group-hover:w-24 transition-all duration-200 overflow-hidden'>
96+
<div className='w-0 group-hover:w-24 duration-200 overflow-hidden'>
9597
<label htmlFor='langSelect' className='sr-only'>
96-
选择语言:
98+
Language Select
9799
</label>
98100
<select
99101
id='langSelect'
@@ -118,7 +120,7 @@ const ThemeSwitch = () => {
118120
<div
119121
className={`${isLoading ? 'opacity-90 ' : 'opacity-0'}
120122
w-screen h-screen glassmorphism bg-black text-white shadow-text flex justify-center items-center
121-
transition-all fixed top-0 left-0 pointer-events-none duration-1000 z-50 shadow-inner`}>
123+
fixed top-0 left-0 pointer-events-none duration-1000 z-50 shadow-inner`}>
122124
<i className='text-3xl mr-5 fas fa-spinner animate-spin' />
123125
</div>
124126
</>

lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
5555
let siteInfo = null
5656

5757
if (global) {
58-
val = global.NOTION_CONFIG?.[key]
5958
siteInfo = global.siteInfo
59+
val = global.NOTION_CONFIG?.[key] || global.THEME_CONFIG?.[key]
6060
}
6161

6262
if (!val) {

lib/db/getSiteData.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getAllPageIds from '@/lib/notion/getAllPageIds'
55
import { getAllTags } from '@/lib/notion/getAllTags'
66
import { getConfigMapFromConfigPage } from '@/lib/notion/getNotionConfig'
77
import getPageProperties, {
8-
adjustPageProperties
8+
adjustPageProperties
99
} from '@/lib/notion/getPageProperties'
1010
import { fetchInBatches, getPage } from '@/lib/notion/getPostBlocks'
1111
import { compressImage, mapImgUrl } from '@/lib/notion/mapImage'
@@ -347,7 +347,6 @@ export function getNavPages({ allPages }) {
347347
return (
348348
post &&
349349
post?.slug &&
350-
!post?.slug?.startsWith('http') &&
351350
post?.type === 'Post' &&
352351
post?.status === 'Published'
353352
)
@@ -526,7 +525,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
526525
return (
527526
post &&
528527
post?.slug &&
529-
!post?.slug?.startsWith('http') &&
528+
// !post?.slug?.startsWith('http') &&
530529
(post?.status === 'Invisible' || post?.status === 'Published')
531530
)
532531
})

lib/global.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
THEMES,
3+
getThemeConfig,
34
initDarkMode,
45
saveDarkModeToLocalStorage
56
} from '@/themes/theme'
@@ -29,11 +30,14 @@ export function GlobalContextProvider(props) {
2930
tagOptions,
3031
NOTION_CONFIG
3132
} = props
33+
3234
const [lang, updateLang] = useState(NOTION_CONFIG?.LANG || LANG) // 默认语言
3335
const [locale, updateLocale] = useState(
3436
generateLocaleDict(NOTION_CONFIG?.LANG || LANG)
3537
) // 默认语言
3638
const [theme, setTheme] = useState(NOTION_CONFIG?.THEME || THEME) // 默认博客主题
39+
const [THEME_CONFIG, SET_THEME_CONFIG] = useState(null) // 主题配置
40+
3741
const defaultDarkMode = NOTION_CONFIG?.APPEARANCE || APPEARANCE
3842
const [isDarkMode, updateDarkMode] = useState(defaultDarkMode === 'dark') // 默认深色模式
3943
const [onLoading, setOnLoading] = useState(false) // 抓取文章数据
@@ -54,6 +58,12 @@ export function GlobalContextProvider(props) {
5458
return newTheme
5559
}
5660

61+
// 抓取主题配置
62+
const updateThemeConfig = async theme => {
63+
const config = await getThemeConfig(theme)
64+
SET_THEME_CONFIG(config)
65+
}
66+
5767
// 切换深色模式
5868
const toggleDarkMode = () => {
5969
const newStatus = !isDarkMode
@@ -99,6 +109,9 @@ export function GlobalContextProvider(props) {
99109
setOnLoading(false)
100110
}
101111

112+
const currentTheme = router?.query?.theme || theme
113+
updateThemeConfig(currentTheme)
114+
102115
router.events.on('routeChangeStart', handleStart)
103116
router.events.on('routeChangeError', handleStop)
104117
router.events.on('routeChangeComplete', handleStop)
@@ -114,6 +127,7 @@ export function GlobalContextProvider(props) {
114127
value={{
115128
fullWidth,
116129
NOTION_CONFIG,
130+
THEME_CONFIG,
117131
toggleDarkMode,
118132
onLoading,
119133
setOnLoading,

lib/notion/getPageProperties.js

+30-25
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import formatDate from '../utils/formatDate'
66
import md5 from 'js-md5'
77
import { siteConfig } from '../config'
88
import {
9-
checkStartWithHttp,
10-
convertUrlStartWithOneSlash,
11-
getLastSegmentFromUrl,
12-
sliceUrlFromHttp
9+
checkStartWithHttp,
10+
convertUrlStartWithOneSlash,
11+
getLastSegmentFromUrl
1312
} from '../utils'
1413
import { extractLangPrefix } from '../utils/pageId'
1514
import { mapImgUrl } from './mapImage'
@@ -188,29 +187,26 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
188187
properties.name = properties.title ?? ''
189188
}
190189

191-
// 开启伪静态路径
192-
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
193-
if (
194-
!properties?.href?.endsWith('.html') &&
195-
!properties?.href?.startsWith('http') &&
196-
properties?.href !== '' &&
197-
properties?.href !== '#' &&
198-
properties?.href !== '/'
199-
) {
200-
properties.href += '.html'
201-
}
202-
}
203-
204-
// 检查处理外链
205-
properties.href = checkStartWithHttp(properties?.href)
206-
? sliceUrlFromHttp(properties?.href)
207-
: convertUrlStartWithOneSlash(properties?.href)
208-
209-
// 设置链接在页内或新页面打开
210-
if (properties.href?.indexOf('http') === 0) {
190+
// http or https 开头的视为外链
191+
if (checkStartWithHttp(properties?.href)) {
192+
properties.href = properties?.slug
211193
properties.target = '_blank'
212194
} else {
213195
properties.target = '_self'
196+
// 伪静态路径右侧拼接.html
197+
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
198+
if (
199+
!properties?.href?.endsWith('.html') &&
200+
properties?.href !== '' &&
201+
properties?.href !== '#' &&
202+
properties?.href !== '/'
203+
) {
204+
properties.href += '.html'
205+
}
206+
}
207+
208+
// 相对路径转绝对路径:url左侧拼接 /
209+
properties.href = convertUrlStartWithOneSlash(properties?.href)
214210
}
215211

216212
// 如果跳转链接是多语言,则在新窗口打开
@@ -239,6 +235,10 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
239235
* @returns
240236
*/
241237
function generateCustomizeSlug(postProperties, NOTION_CONFIG) {
238+
// 外链不处理
239+
if (checkStartWithHttp(postProperties.slug)) {
240+
return postProperties.slug
241+
}
242242
let fullPrefix = ''
243243
const allSlugPatterns = siteConfig(
244244
'POST_URL_PREFIX',
@@ -290,5 +290,10 @@ function generateCustomizeSlug(postProperties, NOTION_CONFIG) {
290290
if (fullPrefix.endsWith('/')) {
291291
fullPrefix = fullPrefix.substring(0, fullPrefix.length - 1) // 去掉尾部部的"/"
292292
}
293-
return `${fullPrefix}/${postProperties.slug ?? postProperties.id}`
293+
294+
if(fullPrefix){
295+
return `${fullPrefix}/${postProperties.slug ?? postProperties.id}`
296+
}else{
297+
return `${postProperties.slug ?? postProperties.id}`
298+
}
294299
}

lib/utils/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export const memorize = Component => {
4747
return memo(MemoizedComponent)
4848
}
4949

50-
// 转换外链
50+
/**
51+
* 诸如 article/https://test.com 等被错误拼接前缀的slug进行处理
52+
* 转换为 https://test.com
53+
* @param {*} str
54+
* @returns
55+
*/
5156
export function sliceUrlFromHttp(str) {
5257
// 检查字符串是否包含http
5358
if (str?.includes('http:') || str?.includes('https:')) {
@@ -99,7 +104,7 @@ export function checkStartWithHttp(str) {
99104
// 检查字符串是否包含http
100105
if (str?.indexOf('http:') === 0 || str?.indexOf('https:') === 0) {
101106
// 如果包含,找到http的位置
102-
return str?.indexOf('http') > -1
107+
return true
103108
} else {
104109
// 不包含
105110
return false

next.config.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ const locales = (function () {
3333
})()
3434

3535
// 编译前执行
36-
const preBuild = (function () {
37-
// 删除 public/sitemap.xml 文件 ; 否则会和/pages/sitemap.xml.js 冲突。
38-
const sitemapPath = path.resolve(__dirname, 'public', 'sitemap.xml')
39-
if (fs.existsSync(sitemapPath)) {
40-
fs.unlinkSync(sitemapPath)
41-
console.log('Deleted existing sitemap.xml from public directory')
42-
}
43-
})()
36+
// const preBuild = (function () {
37+
// // 删除 public/sitemap.xml 文件 ; 否则会和/pages/sitemap.xml.js 冲突。
38+
// const sitemapPath = path.resolve(__dirname, 'public', 'sitemap.xml')
39+
// if (fs.existsSync(sitemapPath)) {
40+
// fs.unlinkSync(sitemapPath)
41+
// console.log('Deleted existing sitemap.xml from public directory')
42+
// }
43+
// })()
4444

4545
/**
4646
* 扫描指定目录下的文件夹名,用于获取所有主题

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "notion-next",
3-
"version": "4.6.0",
3+
"version": "4.6.1",
44
"homepage": "https://github.com/tangly1024/NotionNext.git",
55
"license": "MIT",
66
"repository": {

pages/[prefix]/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export async function getStaticProps({ params: { prefix }, locale }) {
129129
fullSlug += '.html'
130130
}
131131
}
132-
132+
133133
// 在列表内查找文章
134134
props.post = props?.allPages?.find(p => {
135135
return (

pages/category/[category]/page/[page].js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function getStaticPaths() {
7171
// 处理文章页数
7272
const postCount = categoryPosts.length
7373
const totalPages = Math.ceil(
74-
postCount / siteConfig('POSTS_PER_PAGE', 12, NOTION_CONFIG)
74+
postCount / siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG)
7575
)
7676
if (totalPages > 1) {
7777
for (let i = 1; i <= totalPages; i++) {

pages/page/[page].js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function getStaticPaths({ locale }) {
2323
const from = 'page-paths'
2424
const { postCount, NOTION_CONFIG } = await getGlobalData({ from, locale })
2525
const totalPages = Math.ceil(
26-
postCount / siteConfig('POSTS_PER_PAGE', 12, NOTION_CONFIG)
26+
postCount / siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG)
2727
)
2828
return {
2929
// remove first page, we 're not gonna handle that.

pages/sitemap.xml.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const getServerSideProps = async ctx => {
2727
'Cache-Control',
2828
'public, max-age=3600, stale-while-revalidate=59'
2929
)
30-
console.log('fff', fields)
3130
return getServerSideSitemap(ctx, fields)
3231
}
3332

@@ -55,7 +54,7 @@ function generateLocalesSitemap(link, allPages, locale) {
5554
priority: '0.7'
5655
},
5756
{
58-
loc: `${link}${locale}/feed`,
57+
loc: `${link}${locale}/rss/feed.xml`,
5958
lastmod: new Date().toISOString().split('T')[0],
6059
changefreq: 'daily',
6160
priority: '0.7'

pages/tag/[tag]/page/[page].js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function getStaticPaths() {
5656
// 处理文章页数
5757
const postCount = tagPosts.length
5858
const totalPages = Math.ceil(
59-
postCount / siteConfig('POSTS_PER_PAGE', 12, NOTION_CONFIG)
59+
postCount / siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG)
6060
)
6161
if (totalPages > 1) {
6262
for (let i = 1; i <= totalPages; i++) {

public/js/sakura.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/globals.css

+8
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,11 @@ a.avatar-wrapper {
264264
writing-mode: vertical-rl; /* 竖向排列从右向左 */
265265
text-orientation: upright; /* 文字方向正常 */
266266
}
267+
268+
/* Chatbase 在移动端禁止遮挡 */
269+
@media (max-width: 700px) {
270+
button#chatbase-bubble-button {
271+
margin-bottom: 42px;
272+
margin-right: 20px;
273+
}
274+
}

themes/commerce/components/BlogPostListPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ProductCard from './ProductCard'
1414
*/
1515
const BlogPostListPage = ({ page = 1, posts = [], postCount, siteInfo }) => {
1616
const { NOTION_CONFIG } = useGlobal()
17-
const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', 12, NOTION_CONFIG)
17+
const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG)
1818
const totalPage = Math.ceil(postCount / POSTS_PER_PAGE)
1919
const showPagination = postCount >= POSTS_PER_PAGE
2020
if (!posts || posts.length === 0 || page > totalPage) {

themes/commerce/components/BlogPostListScroll.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const BlogPostListScroll = ({
2020
siteInfo
2121
}) => {
2222
const { NOTION_CONFIG } = useGlobal()
23-
const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', 12, NOTION_CONFIG)
23+
const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG)
2424

2525
const [page, updatePage] = useState(1)
2626
const postsToShow = getListByPage(posts, page, POSTS_PER_PAGE)

themes/example/components/BlogListPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const BlogListPage = props => {
1414
const { locale, NOTION_CONFIG } = useGlobal()
1515
const router = useRouter()
1616
const totalPage = Math.ceil(
17-
postCount / siteConfig('POSTS_PER_PAGE', 12, NOTION_CONFIG)
17+
postCount / siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG)
1818
)
1919
const currentPage = +page
2020

0 commit comments

Comments
 (0)