1
0
mirror of synced 2025-12-19 18:10:59 -05:00

add carousel item version check (#58134)

This commit is contained in:
Robert Sese
2025-10-22 19:48:37 -05:00
committed by GitHub
parent d7f195c299
commit a1ed181c24
2 changed files with 55 additions and 1 deletions

View File

@@ -132,7 +132,11 @@ async function resolveRecommended(
try { try {
const foundPage = tryResolveArticlePath(rawPath, page?.relativePath, req) const foundPage = tryResolveArticlePath(rawPath, page?.relativePath, req)
if (foundPage) { if (
foundPage &&
(!req.context?.currentVersion ||
foundPage.applicableVersions.includes(req.context.currentVersion))
) {
const href = getPageHref(foundPage) const href = getPageHref(foundPage)
const category = foundPage.relativePath const category = foundPage.relativePath
? foundPage.relativePath.split('/').slice(0, -1).filter(Boolean) ? foundPage.relativePath.split('/').slice(0, -1).filter(Boolean)

View File

@@ -29,6 +29,8 @@ describe('resolveRecommended middleware', () => {
}, },
}, },
redirects: {}, redirects: {},
currentVersion: 'free-pro-team@latest',
currentLanguage: 'en',
...contextData, ...contextData,
}, },
}) as ExtendedRequest }) as ExtendedRequest
@@ -316,4 +318,52 @@ describe('resolveRecommended middleware', () => {
]) ])
expect(mockNext).toHaveBeenCalled() expect(mockNext).toHaveBeenCalled()
}) })
test('should filter out articles not available in current version', async () => {
// Create a test page that is only available in fpt, not ghec
const fptOnlyPage: Partial<import('@/types').Page> = {
mtime: Date.now(),
title: 'FPT Only Article',
rawTitle: 'FPT Only Article',
intro: 'This article is only for FPT',
rawIntro: 'This article is only for FPT',
relativePath: 'test/fpt-only.md',
fullPath: '/full/path/test/fpt-only.md',
languageCode: 'en',
documentType: 'article',
markdown: 'FPT only content',
versions: { fpt: '*' }, // Only available in free-pro-team
applicableVersions: ['free-pro-team@latest'], // Not available in ghec
permalinks: [
{
languageCode: 'en',
pageVersion: 'free-pro-team@latest',
title: 'FPT Only Article',
href: '/en/test/fpt-only',
hrefWithoutLanguage: '/test/fpt-only',
},
],
renderProp: vi.fn().mockResolvedValue('rendered'),
renderTitle: vi.fn().mockResolvedValue('FPT Only Article'),
render: vi.fn().mockResolvedValue('rendered content'),
buildRedirects: vi.fn().mockReturnValue({}),
}
mockFindPage.mockReturnValue(fptOnlyPage as any)
// Create a request context where we're viewing the GHEC version
const req = createMockRequest(
{ rawRecommended: ['/test/fpt-only'] },
{
currentVersion: 'enterprise-cloud@latest', // Current context is GHEC, not FPT
currentLanguage: 'en',
},
)
await resolveRecommended(req, mockRes, mockNext)
// The recommended array should be empty since the article isn't available in enterprise-cloud
expect((req.context!.page as any).recommended).toEqual([])
expect(mockNext).toHaveBeenCalled()
})
}) })