-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix root directory spread pagination
url.prev
for first page (#6183)
* Fix root pagination `url.prev` for first page * fix lockfile? * add changeset
- Loading branch information
Dan Jutan
authored
Feb 9, 2023
1 parent
a64a800
commit 436bd09
Showing
6 changed files
with
69 additions
and
3 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,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fixes the first-page value of `url.prev` when paginating a spread route at the root |
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
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,33 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Pagination root', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/astro-pagination-root-spread/', | ||
site: 'https://mysite.dev/', | ||
base: '/blog', | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('correct prev url in root spread', async () => { | ||
const prevMap = { | ||
'/4/': '/3', | ||
'/3/': '/2', | ||
'/2/': '/', | ||
'/': undefined, | ||
}; | ||
|
||
await Promise.all( | ||
Object.entries(prevMap).map(async ([curr, prev]) => { | ||
const html = await fixture.readFile(curr + 'index.html'); | ||
const $ = cheerio.load(html); | ||
expect($('#prev').attr('href')).to.equal(prev); | ||
}) | ||
); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/astro-pagination-root-spread/package.json
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 @@ | ||
{ | ||
"name": "@test/astro-pagination-root", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/astro/test/fixtures/astro-pagination-root-spread/src/pages/[...page].astro
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,16 @@ | ||
--- | ||
export async function getStaticPaths({ paginate }) { | ||
const astronautPages = [{ | ||
astronaut: 'Neil Armstrong', | ||
}, { | ||
astronaut: 'Buzz Aldrin', | ||
}, { | ||
astronaut: 'Sally Ride', | ||
}, { | ||
astronaut: 'John Glenn', | ||
}]; | ||
return paginate(astronautPages, { pageSize: 1 }); | ||
} | ||
const { page } = Astro.props; | ||
--- | ||
<a id="prev" href={page.url.prev}>Back</a> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.