Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/frame/middleware/resolve-recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ async function resolveRecommended(
try {
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 category = foundPage.relativePath
? foundPage.relativePath.split('/').slice(0, -1).filter(Boolean)
Expand Down
50 changes: 50 additions & 0 deletions src/frame/tests/resolve-recommended.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('resolveRecommended middleware', () => {
},
},
redirects: {},
currentVersion: 'free-pro-team@latest',
currentLanguage: 'en',
...contextData,
},
}) as ExtendedRequest
Expand Down Expand Up @@ -316,4 +318,52 @@ describe('resolveRecommended middleware', () => {
])
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()
})
})
Loading