Skip to content

Commit 0dcb49d

Browse files
kforristangly1024
andauthored
fix(notion): 修复 Invisible 页面菜单映射 (#4372)
Co-authored-by: tangly1024 <mail@tangly1024.com>
1 parent 762b65e commit 0dcb49d

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

__tests__/lib/db/SiteDataApi.customMenu.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,55 @@ describe('getCustomMenu', () => {
122122

123123
expect(menus[0].href).toBe('/guide')
124124
})
125+
126+
it('uses the generated href when a menu explicitly targets an invisible page', () => {
127+
const collectionData = [
128+
{
129+
id: 'page-pending',
130+
type: 'Page',
131+
status: 'Invisible',
132+
slug: 'pending'
133+
},
134+
{
135+
id: 'menu-pending',
136+
type: 'Menu',
137+
status: 'Published',
138+
title: 'Pending',
139+
slug: 'pending',
140+
href: '/pending'
141+
}
142+
]
143+
const sourcePageSlugs = getSourcePageSlugs(collectionData)
144+
collectionData[0].slug = 'pending/2026/07/29/pending'
145+
collectionData[0].href = '/pending/2026/07/29/pending'
146+
147+
const menus = getCustomMenu({ collectionData, sourcePageSlugs })
148+
149+
expect(menus[0].href).toBe('/pending/2026/07/29/pending')
150+
})
151+
152+
it('does not expose an unpublished page through a matching menu slug', () => {
153+
const collectionData = [
154+
{
155+
id: 'page-draft',
156+
type: 'Page',
157+
status: 'Draft',
158+
slug: 'draft',
159+
href: '/manual/draft'
160+
},
161+
{
162+
id: 'menu-draft',
163+
type: 'Menu',
164+
status: 'Published',
165+
title: 'Draft',
166+
slug: 'draft',
167+
href: '/draft'
168+
}
169+
]
170+
const sourcePageSlugs = getSourcePageSlugs(collectionData)
171+
172+
const menus = getCustomMenu({ collectionData, sourcePageSlugs })
173+
174+
expect(menus[0].href).toBe('/draft')
175+
})
125176
})

lib/db/notion/getCustomMenu.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ function getPageHrefBySourceSlug(collectionData, sourcePageSlugs) {
2828
const ambiguousSlugs = new Set()
2929

3030
collectionData.forEach(page => {
31-
if (page?.type !== 'Page' || page?.status !== 'Published' || !page?.href) {
31+
const isDirectlyRoutable =
32+
page?.status === 'Published' || page?.status === 'Invisible'
33+
if (page?.type !== 'Page' || !isDirectlyRoutable || !page?.href) {
3234
return
3335
}
3436

0 commit comments

Comments
 (0)