-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes an edge case in custom pagination link processing (#2105)
Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
111 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@astrojs/starlight': patch | ||
--- | ||
|
||
Fixes an edge case in custom pagination link processing | ||
|
||
Custom link values for `prev`/`next` in page frontmatter are now always used as authored. | ||
Previously this was not the case in some edge cases such as for the first and final pages in the sidebar. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/starlight/__tests__/basics/pagination-with-base.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'; | ||
import type { | ||
getPrevNextLinks as getPrevNextLinksType, | ||
getSidebar as getSidebarType, | ||
} from '../../utils/navigation'; | ||
|
||
vi.mock('astro:content', async () => | ||
(await import('../test-utils')).mockedAstroContent({ | ||
docs: [ | ||
['index.mdx', { title: 'Home Page' }], | ||
['environmental-impact.md', { title: 'Eco-friendly docs' }], | ||
['guides/authoring-content.md', { title: 'Authoring Markdown' }], | ||
['guides/components.mdx', { title: 'Components' }], | ||
['reference/frontmatter.md', { title: 'Frontmatter Reference' }], | ||
], | ||
}) | ||
); | ||
|
||
describe('without base', async () => { | ||
let getPrevNextLinks: typeof getPrevNextLinksType; | ||
let getSidebar: typeof getSidebarType; | ||
let sidebar: ReturnType<typeof getSidebar>; | ||
|
||
beforeAll(async () => { | ||
({ getPrevNextLinks, getSidebar } = await import('../../utils/navigation')); | ||
sidebar = getSidebar('/reference/frontmatter/', undefined); | ||
}); | ||
|
||
test('pagination links are inferred correctly with no frontmatter', () => { | ||
const links = getPrevNextLinks(sidebar, true, {}); | ||
expect(links.prev?.href).toBe('/guides/components/'); | ||
expect(links.next?.href).toBeUndefined(); | ||
}); | ||
|
||
test('pagination links are used as authored with custom links in frontmatter', () => { | ||
const prevLink = '/other-page'; | ||
const nextLink = '/extra-page'; | ||
const links = getPrevNextLinks(sidebar, true, { | ||
prev: { link: prevLink, label: 'Other Page' }, | ||
next: { link: nextLink, label: 'Extra Page' }, | ||
}); | ||
expect(links.prev?.href).toBe(prevLink); | ||
expect(links.next?.href).toBe(nextLink); | ||
}); | ||
}); | ||
|
||
describe('with base', () => { | ||
let getPrevNextLinks: typeof getPrevNextLinksType; | ||
let getSidebar: typeof getSidebarType; | ||
let sidebar: ReturnType<typeof getSidebar>; | ||
|
||
beforeAll(async () => { | ||
vi.resetModules(); | ||
vi.stubEnv('BASE_URL', '/test-base/'); | ||
({ getPrevNextLinks, getSidebar } = await import('../../utils/navigation')); | ||
sidebar = getSidebar('/test-base/reference/frontmatter/', undefined); | ||
}); | ||
|
||
afterAll(() => { | ||
vi.unstubAllEnvs(); | ||
vi.resetModules(); | ||
}); | ||
|
||
test('pagination links are inferred correctly with no frontmatter', () => { | ||
const links = getPrevNextLinks(sidebar, true, {}); | ||
expect(links.prev?.href).toBe('/test-base/guides/components/'); | ||
expect(links.next?.href).toBeUndefined(); | ||
}); | ||
|
||
test('pagination links are used as authored with custom links in frontmatter', () => { | ||
const prevLink = '/other-page'; | ||
const nextLink = '/extra-page'; | ||
const links = getPrevNextLinks(sidebar, true, { | ||
prev: { link: prevLink, label: 'Other Page' }, | ||
next: { link: nextLink, label: 'Extra Page' }, | ||
}); | ||
expect(links.prev?.href).toBe(prevLink); | ||
expect(links.next?.href).toBe(nextLink); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters