Skip to content

Commit e2b7a34

Browse files
authored
Merge pull request #3802 from tangly1024/release/4.9.3.1
文章路由错乱bug
2 parents 5f1d83f + 6b25ef0 commit e2b7a34

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

lib/db/SiteDataApi.js

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ const EmptyData = pageId => {
159159
* ✅ 兼容 prefix / slug / suffix 任意组合
160160
* ⚠️ 只能在 getStaticProps / getServerSideProps 使用
161161
*/
162+
/**
163+
* 生产级稳定版本
164+
* 严格精确匹配,不做模糊匹配
165+
*/
162166
export async function resolvePostProps({
163167
prefix,
164168
slug,
@@ -167,59 +171,51 @@ export async function resolvePostProps({
167171
from,
168172
}) {
169173
/**
170-
* 1️⃣ 统一路径片段
174+
* 1️⃣ 统一路径
171175
*/
172176
const segments = []
173177
if (prefix) segments.push(prefix)
174178
if (slug) segments.push(slug)
175179
if (Array.isArray(suffix)) segments.push(...suffix)
176180

177181
const fullSlug = segments.join('/')
178-
const source = from || `slug-props-${fullSlug}`
179-
180-
/**
181-
* 2️⃣ 构造所有可能命中的 slug
182-
*/
183182
const lastSegment = segments[segments.length - 1]
184-
185-
const slugCandidates = new Set([
186-
fullSlug,
187-
lastSegment,
188-
slug,
189-
prefix,
190-
])
191-
192-
// 去掉 falsy
193-
for (const s of Array.from(slugCandidates)) {
194-
if (!s) slugCandidates.delete(s)
195-
}
183+
const source = from || `slug-props-${fullSlug}`
196184

197185
/**
198-
* 3️⃣ 拉取全局数据
186+
* 2️⃣ 拉全局数据
199187
*/
200188
const props = await fetchGlobalAllData({ from: source, locale })
201189

202190
let post = null
203191

204192
/**
205-
* 4️⃣ 列表内匹配
193+
* 3️⃣ 一级匹配:完整 slug 精确匹配(核心)
206194
*/
207-
post = props?.allPages?.find(p => {
208-
if (!p || p?.type?.includes('Menu')) return false
195+
if (fullSlug) {
196+
post = props?.allPages?.find(p => {
197+
if (!p || p?.type?.includes('Menu')) return false
198+
return p.slug === fullSlug
199+
})
200+
}
209201

210-
return (
211-
slugCandidates.has(p.slug) ||
212-
slugCandidates.has(p.slug?.split('/').pop()) ||
213-
slugCandidates.has(p.id) ||
214-
slugCandidates.has(idToUuid(p.id)) ||
215-
slugCandidates.has(idToUuid(fullSlug))
216-
)
217-
})
202+
/**
203+
* 4️⃣ 二级匹配:完整 UUID 精确匹配
204+
*/
205+
if (!post && fullSlug) {
206+
post = props?.allPages?.find(p => {
207+
return p?.id === fullSlug
208+
})
209+
}
218210

219211
/**
220-
* 5️⃣ 非列表文章兜底(pageId)
212+
* 5️⃣ 三级匹配:如果最后一段是 UUID,直接拉 Notion
221213
*/
222-
if (!post && typeof lastSegment === 'string' && lastSegment.length >= 32) {
214+
if (
215+
!post &&
216+
typeof lastSegment === 'string' &&
217+
/^[a-f0-9-]{32,36}$/i.test(lastSegment)
218+
) {
223219
try {
224220
post = await fetchPageFromNotion(lastSegment)
225221
} catch (e) {
@@ -228,17 +224,14 @@ export async function resolvePostProps({
228224
}
229225

230226
/**
231-
* 6️⃣ blockMap 兜底
227+
* 6️⃣ 如果拿到了 post,但没有 blockMap,则拉 block
232228
*/
233-
if (post && post.id && !post?.blockMap) {
229+
if (post?.id && !post?.blockMap) {
234230
try {
235-
236231
const rawBlockMap = await fetchNotionPageBlocks(post.id, source)
237232

238-
// Notion修改了数据格式再次做统一兼容
239233
post.blockMap = adapterNotionBlockMap(rawBlockMap)
240234

241-
// 格式化内容,部分的样式字段格式在此处理
242235
post.blockMap = {
243236
...post.blockMap,
244237
block: formatNotionBlock(post.blockMap.block)
@@ -268,6 +261,7 @@ export async function resolvePostProps({
268261
return props
269262
}
270263

264+
271265
/**
272266
* 将Notion数据转站点数据
273267
* 这里统一对数据格式化

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "notion-next",
3-
"version": "4.9.3",
3+
"version": "4.9.3.1",
44
"homepage": "https://github.com/tangly1024/NotionNext.git",
55
"license": "MIT",
66
"engines": {

0 commit comments

Comments
 (0)