diff options
author | 2022-08-23 08:47:20 -0400 | |
---|---|---|
committer | 2022-08-23 08:47:20 -0400 | |
commit | f40065f510b4fef40d3d3e069e8dc2d4d9a4edb2 (patch) | |
tree | 8311bf8816b3ffa249688d73d75b6ad5d30c1514 | |
parent | 8164fa6f1a01152f00542be33baebecd8ac60818 (diff) | |
download | astro-f40065f510b4fef40d3d3e069e8dc2d4d9a4edb2.tar.gz astro-f40065f510b4fef40d3d3e069e8dc2d4d9a4edb2.tar.zst astro-f40065f510b4fef40d3d3e069e8dc2d4d9a4edb2.zip |
Ensure index pages are generated on paginated results (#4426)
* Ensure index pages are generated on paginated results
* Changeset
-rw-r--r-- | .changeset/odd-elephants-remember.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/build/generate.ts | 5 | ||||
-rw-r--r-- | packages/astro/test/fixtures/get-static-paths-pages/package.json | 8 | ||||
-rw-r--r-- | packages/astro/test/fixtures/get-static-paths-pages/src/pages/[...page].astro | 37 | ||||
-rw-r--r-- | packages/astro/test/get-static-paths-pages.test.js | 27 | ||||
-rw-r--r-- | pnpm-lock.yaml | 6 |
6 files changed, 83 insertions, 5 deletions
diff --git a/.changeset/odd-elephants-remember.md b/.changeset/odd-elephants-remember.md new file mode 100644 index 000000000..c75dcf4c2 --- /dev/null +++ b/.changeset/odd-elephants-remember.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Ensure index pages are generated on paginated results diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index cced45479..68da189fa 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -207,11 +207,6 @@ async function getPathsForRoute( paths = result.staticPaths .map((staticPath) => staticPath.params && route.generate(staticPath.params)) .filter((staticPath) => { - // Remove empty or undefined paths - if (!staticPath) { - return false; - } - // The path hasn't been built yet, include it if (!builtPaths.has(removeTrailingForwardSlash(staticPath))) { return true; diff --git a/packages/astro/test/fixtures/get-static-paths-pages/package.json b/packages/astro/test/fixtures/get-static-paths-pages/package.json new file mode 100644 index 000000000..8f600c631 --- /dev/null +++ b/packages/astro/test/fixtures/get-static-paths-pages/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/get-static-paths-pages", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/get-static-paths-pages/src/pages/[...page].astro b/packages/astro/test/fixtures/get-static-paths-pages/src/pages/[...page].astro new file mode 100644 index 000000000..47159e911 --- /dev/null +++ b/packages/astro/test/fixtures/get-static-paths-pages/src/pages/[...page].astro @@ -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> diff --git a/packages/astro/test/get-static-paths-pages.test.js b/packages/astro/test/get-static-paths-pages.test.js new file mode 100644 index 000000000..dd8499ae4 --- /dev/null +++ b/packages/astro/test/get-static-paths-pages.test.js @@ -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'); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 90111499c..c19dc7e09 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1534,6 +1534,12 @@ importers: '@fontsource/montserrat': 4.5.11 astro: link:../../.. + packages/astro/test/fixtures/get-static-paths-pages: + specifiers: + astro: workspace:* + dependencies: + astro: link:../../.. + packages/astro/test/fixtures/glob-pages-css: specifiers: astro: workspace:* |