-
-
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.
Ensure index pages are generated on paginated results (#4426)
* Ensure index pages are generated on paginated results * Changeset
- Loading branch information
Showing
6 changed files
with
83 additions
and
5 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 | ||
--- | ||
|
||
Ensure index pages are generated on paginated results |
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
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/get-static-paths-pages/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/get-static-paths-pages", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/astro/test/fixtures/get-static-paths-pages/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,37 @@ | ||
--- | ||
export async function getStaticPaths({ paginate }) { | ||
const astronautPages = [{ | ||
astronaut: 'Neil Armstrong', | ||
}, { | ||
astronaut: 'Buzz Aldrin', | ||
}, { | ||
astronaut: 'Sally Ride', | ||
}, { | ||
astronaut: 'John Glenn', | ||
}]; | ||
// Generate pages from our array of astronauts, with 2 to a page | ||
return paginate(astronautPages, { pageSize: 2 }); | ||
} | ||
// All paginated data is passed on the "page" prop | ||
const { page } = Astro.props; | ||
--- | ||
|
||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<meta name="generator" content={Astro.generator} /> | ||
<title>Astro</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Page {page.currentPage}</h1> | ||
<ul> | ||
<!--List the array of astronaut info--> | ||
{page.data.map(({ astronaut }: { astronaut: string }) => <li>{astronaut}</li>)} | ||
</ul> | ||
</body> | ||
|
||
</html> |
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,27 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('getStaticPaths with trailingSlash: ignore', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/get-static-paths-pages/', | ||
site: 'https://mysite.dev/', | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('includes index page', async () => { | ||
let html = await fixture.readFile('/index.html'); | ||
let $ = cheerio.load(html); | ||
expect($('h1').text()).to.equal('Page 1'); | ||
}); | ||
|
||
it('includes paginated page', async () => { | ||
let html = await fixture.readFile('/2/index.html'); | ||
let $ = cheerio.load(html); | ||
expect($('h1').text()).to.equal('Page 2'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.