Fix root directory spread pagination url.prev
for first page (#6183)
* Fix root pagination `url.prev` for first page * fix lockfile? * add changeset
This commit is contained in:
parent
a64a800d9b
commit
436bd09341
6 changed files with 69 additions and 3 deletions
5
.changeset/calm-readers-learn.md
Normal file
5
.changeset/calm-readers-learn.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes the first-page value of `url.prev` when paginating a spread route at the root
|
|
@ -63,9 +63,7 @@ export function generatePaginateFunction(routeMatch: RouteData): PaginateFunctio
|
||||||
: routeMatch.generate({
|
: routeMatch.generate({
|
||||||
...params,
|
...params,
|
||||||
page:
|
page:
|
||||||
!includesFirstPageNumber && pageNum - 1 === 1
|
!includesFirstPageNumber && pageNum - 1 === 1 ? '' : String(pageNum - 1),
|
||||||
? undefined
|
|
||||||
: String(pageNum - 1),
|
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
} as Page,
|
} as Page,
|
||||||
|
|
33
packages/astro/test/astro-pagination-root-spread.test.js
Normal file
33
packages/astro/test/astro-pagination-root-spread.test.js
Normal file
|
@ -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
packages/astro/test/fixtures/astro-pagination-root-spread/package.json
vendored
Normal file
8
packages/astro/test/fixtures/astro-pagination-root-spread/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"name": "@test/astro-pagination-root",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
16
packages/astro/test/fixtures/astro-pagination-root-spread/src/pages/[...page].astro
vendored
Normal file
16
packages/astro/test/fixtures/astro-pagination-root-spread/src/pages/[...page].astro
vendored
Normal file
|
@ -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>
|
|
@ -1482,6 +1482,12 @@ importers:
|
||||||
dependencies:
|
dependencies:
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
|
|
||||||
|
packages/astro/test/fixtures/astro-pagination-root-spread:
|
||||||
|
specifiers:
|
||||||
|
astro: workspace:*
|
||||||
|
dependencies:
|
||||||
|
astro: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/astro-partial-html:
|
packages/astro/test/fixtures/astro-partial-html:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@astrojs/react': workspace:*
|
'@astrojs/react': workspace:*
|
||||||
|
|
Loading…
Reference in a new issue