Skip to content

Commit a3ba16e

Browse files
authored
Merge branch 'main' into main
2 parents 5e9c686 + 661e66e commit a3ba16e

104 files changed

Lines changed: 7147 additions & 867 deletions

File tree

Some content is hidden

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

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# These are supported funding model platforms
22
ko_fi: tangly1024
3+
buy_me_a_coffee: tangly1024

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.20.0
1+
20.18.0

DEPLOYMENT.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ NotionNext 支持多种部署方式,本指南将详细介绍各种部署选项
88

99
### 0. 本地统一基线(推荐)
1010

11-
为提升跨平台兼容性(Vercel / Cloudflare Pages / Netlify),本项目建议统一使用以下最简流程:
11+
为提升跨平台兼容性(Vercel / Cloudflare Pages / Netlify / EdgeOne Pages 等),本项目建议统一使用以下最简流程:
1212

1313
```bash
14-
# Node 20
15-
nvm use || nvm install 20.20.0
14+
# Node 20(版本以仓库根目录 `.nvmrc` 为准,便于与各平台预装列表对齐)
15+
nvm use || nvm install
1616

1717
# Yarn
1818
npm i -g yarn
@@ -195,6 +195,18 @@ netlify deploy --prod --dir=out
195195
status = 301
196196
```
197197

198+
## 腾讯云 EdgeOne Pages
199+
200+
EdgeOne 构建阶段会按仓库中的 `.nvmrc` 切换 Node 版本。若控制台报错类似 **Failed to switch to Node.js x.y.z**,通常是因为平台上 **未提供该补丁版本**(例如仅有 `20.18.0`,而旧版本 `.nvmrc` 写了 `20.20.0`)。
201+
202+
处理方式:
203+
204+
1. **保持上游**:拉取最新 NotionNext,确认 `.nvmrc` 已与 EdgeOne「项目设置 → Node.js 版本」下拉列表中可选版本一致(一般为当前文件中的 `20.18.x`)。
205+
2. **自建仓库**:在 EdgeOne 控制台选择与 `.nvmrc` **完全一致**的 Node 版本;仍失败时检查构建日志是否仍在读取旧的 `.nvmrc`(需推送后再构建)。
206+
3. `package.json``engines.node``>=20 <25`,在 Node 20 系列内均可构建;关键是 **构建环境实际安装的版本**能解析 `.nvmrc`
207+
208+
构建命令与静态导出等与其它平台相同,按需配置环境变量(至少 `NOTION_PAGE_ID`)。
209+
198210
## Docker 部署
199211

200212
### Dockerfile

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 环境要求
66

7-
- Node.js = 20.20.0(使用 `.nvmrc` 保持一致
7+
- Node.js 20 LTS(具体补丁版本以仓库根目录 `.nvmrc` 为准,与各托管平台预装 Node 对齐
88
- Yarn = 1.22.22(使用 `package.json#packageManager` 保持一致)
99
- Git
1010

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Notion是一个能让效率暴涨的生产力引擎,可以帮你书写文档
4040

4141
```bash
4242
# 1) 使用 Node 20(建议先安装 nvm)
43-
nvm use || nvm install 20.20.0
43+
nvm use || nvm install
4444

4545
# 2) 安装 Yarn(若未安装)
4646
npm i -g yarn

README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ A static blog system built with NextJS and Notion API, deployed on Vercel. Desig
3939

4040
```bash
4141
# 1) Use Node 20 (nvm recommended)
42-
nvm use || nvm install 20.20.0
42+
nvm use || nvm install
4343

4444
# 2) Install Yarn if needed
4545
npm i -g yarn
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
stripTransientQueryParamsFromAsPath,
3+
stripTransientQueryParamsFromUrl
4+
} from '@/lib/utils/stripTransientUrlParams'
5+
6+
describe('stripTransientQueryParamsFromUrl', () => {
7+
it('removes giscus and target from full URL', () => {
8+
const u =
9+
'https://blog.example.com/post/foo?giscus=abc&x=1&target=comment#h'
10+
const out = stripTransientQueryParamsFromUrl(u)
11+
expect(out).toBe('https://blog.example.com/post/foo?x=1#h')
12+
})
13+
})
14+
15+
describe('stripTransientQueryParamsFromAsPath', () => {
16+
it('strips giscus from asPath', () => {
17+
expect(stripTransientQueryParamsFromAsPath('/a/b?giscus=1')).toBe('/a/b')
18+
})
19+
it('preserves other query and hash', () => {
20+
expect(
21+
stripTransientQueryParamsFromAsPath('/p?k=1&giscus=x#c')
22+
).toBe('/p?k=1#c')
23+
})
24+
})

components/Comment.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Tabs from '@/components/Tabs'
22
import { siteConfig } from '@/lib/config'
33
import { isBrowser, isSearchEngineBot } from '@/lib/utils'
4+
import { stripTransientQueryParamsFromAsPath } from '@/lib/utils/stripTransientUrlParams'
45
import dynamic from 'next/dynamic'
56
import { useRouter } from 'next/router'
67
import { useEffect, useRef, useState } from 'react'
@@ -49,19 +50,29 @@ const Comment = ({ frontMatter, className }) => {
4950
}
5051
}, [frontMatter])
5152

52-
// 当连接中有特殊参数时跳转到评论区
53-
if (
54-
isBrowser &&
55-
('giscus' in router.query || router.query.target === 'comment')
56-
) {
57-
setTimeout(() => {
58-
const url = router.asPath.replace('?target=comment', '')
59-
history.replaceState({}, '', url)
60-
document
61-
?.getElementById('comment')
62-
?.scrollIntoView({ block: 'start', behavior: 'smooth' })
63-
}, 1000)
64-
}
53+
useEffect(() => {
54+
if (!isBrowser || !router.isReady) {
55+
return
56+
}
57+
const hasGiscus = 'giscus' in router.query
58+
const scrollComment = router.query.target === 'comment'
59+
if (!hasGiscus && !scrollComment) {
60+
return
61+
}
62+
const cleanPath = stripTransientQueryParamsFromAsPath(router.asPath)
63+
window.history.replaceState(window.history.state, '', cleanPath)
64+
router
65+
.replace(cleanPath, undefined, { scroll: false, shallow: true })
66+
.catch(() => {})
67+
if (scrollComment || hasGiscus) {
68+
const t = window.setTimeout(() => {
69+
document
70+
?.getElementById('comment')
71+
?.scrollIntoView({ block: 'start', behavior: 'smooth' })
72+
}, 400)
73+
return () => window.clearTimeout(t)
74+
}
75+
}, [router.isReady, router.asPath, router.query])
6576

6677
if (!frontMatter) {
6778
return null

components/Giscus.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { siteConfig } from '@/lib/config'
22
import { useGlobal } from '@/lib/global'
33
import { loadExternalResource } from '@/lib/utils'
4+
import { stripTransientQueryParamsFromAsPath } from '@/lib/utils/stripTransientUrlParams'
5+
import Router from 'next/router'
46
import { useEffect } from 'react'
57
// import Giscus from '@giscus/react'
68

@@ -15,12 +17,30 @@ const GiscusComponent = () => {
1517
const { isDarkMode } = useGlobal()
1618
const theme = isDarkMode ? 'dark' : 'light'
1719
useEffect(() => {
20+
const syncGiscusQueryOutOfUrl = () => {
21+
if (typeof window === 'undefined') {
22+
return
23+
}
24+
const full = `${window.location.pathname}${window.location.search}${window.location.hash}`
25+
const clean = stripTransientQueryParamsFromAsPath(full)
26+
if (clean === full) {
27+
return
28+
}
29+
window.history.replaceState(window.history.state, '', clean)
30+
Router.replace(clean, undefined, { scroll: false, shallow: true }).catch(() => {})
31+
}
32+
1833
loadExternalResource('/js/giscus.js', 'js').then(() => {
1934
if (window?.Giscus?.init) {
2035
window?.Giscus?.init('#giscus')
2136
}
37+
syncGiscusQueryOutOfUrl()
2238
})
39+
40+
const onRouteDone = () => syncGiscusQueryOutOfUrl()
41+
Router.events.on('routeChangeComplete', onRouteDone)
2342
return () => {
43+
Router.events.off('routeChangeComplete', onRouteDone)
2444
window?.Giscus?.destroy()
2545
}
2646
}, [isDarkMode])

components/NotionPage.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,6 @@ const NotionPage = ({ post, className }) => {
104104
})
105105
})
106106
}
107-
108-
// 查找所有具有 'notion-collection-page-properties' 类的元素,删除notion自带的页面properties
109-
const timer = setTimeout(() => {
110-
// 查找所有具有 'notion-collection-page-properties' 类的元素
111-
const elements = document.querySelectorAll(
112-
'.notion-collection-page-properties'
113-
)
114-
115-
// 遍历这些元素并将其从 DOM 中移除
116-
elements?.forEach(element => {
117-
element?.remove()
118-
})
119-
}, 1000) // 1000 毫秒 = 1 秒
120-
121-
// 清理定时器,防止组件卸载时执行
122-
return () => clearTimeout(timer)
123107
}, [post])
124108

125109
// const cleanBlockMap = cleanBlocksWithWarn(post?.blockMap);
@@ -261,7 +245,7 @@ const Equation = dynamic(
261245
await import('@/lib/plugins/mhchem')
262246
return m.Equation
263247
}),
264-
{ ssr: false }
248+
{ ssr: true }
265249
)
266250

267251
// 原版文档

0 commit comments

Comments
 (0)