summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar FredKSchott <FredKSchott@users.noreply.github.com> 2021-08-11 22:05:17 +0000
committerGravatar GitHub Actions <actions@github.com> 2021-08-11 22:05:17 +0000
commitb63960f514851ff6d61d722fd698a36020ddc347 (patch)
tree878973594f55e1b8d1528008a74fa7e4a11cb419
parent0f0cc2b9d83ffeee125b85c95d2d51080f21074d (diff)
downloadastro-b63960f514851ff6d61d722fd698a36020ddc347.tar.gz
astro-b63960f514851ff6d61d722fd698a36020ddc347.tar.zst
astro-b63960f514851ff6d61d722fd698a36020ddc347.zip
[ci] yarn format
-rw-r--r--docs/src/pages/core-concepts/routing.md2
-rw-r--r--docs/src/pages/guides/pagination.md5
-rw-r--r--packages/astro/src/build/page.ts10
-rw-r--r--packages/astro/src/build/paginate.ts3
-rw-r--r--packages/astro/src/runtime.ts14
-rw-r--r--packages/astro/test/astro-pagination.test.js1
6 files changed, 17 insertions, 18 deletions
diff --git a/docs/src/pages/core-concepts/routing.md b/docs/src/pages/core-concepts/routing.md
index 712a2fba8..42ed0d35d 100644
--- a/docs/src/pages/core-concepts/routing.md
+++ b/docs/src/pages/core-concepts/routing.md
@@ -24,8 +24,6 @@ Sometimes, you need to generate many URLs from a single page component. Astro us
An important thing to keep in mind: Astro is a static site builder. There is no Astro server to run in production, which means that every page must be built ahead of time. Pages that use dynamic routes must export a `getStaticPaths()` function which will tell Astro exactly what pages to generate. Learn more by viewing the complete [API Reference](/reference/api-reference#getstaticpaths).
-
-
### Named parameters
Dynamic parameters are encoded into the filename using `[bracket]` notation:
diff --git a/docs/src/pages/guides/pagination.md b/docs/src/pages/guides/pagination.md
index bcce12e6b..8c1b0e638 100644
--- a/docs/src/pages/guides/pagination.md
+++ b/docs/src/pages/guides/pagination.md
@@ -7,7 +7,7 @@ Astro supports built-in, automatic pagination for large collections of data that
## When to use pagination
-Pagination is only useful when you need to generate multiple, numbered pages from a larger data set.
+Pagination is only useful when you need to generate multiple, numbered pages from a larger data set.
If all of your data can fit on a single page then you should consider using a static [page component](/core-concepts/astro-pages) instead.
@@ -72,7 +72,6 @@ The `page` prop has several useful properties, but the most important one is `pa
The `page` prop includes other helpful metadata, like `page.url.next`, `page.url.prev`, `page.total`, and more. See our [API reference](/reference/api-reference#the-pagination-page-prop) for the full `page` interface.
-
## Nested pagination
A more advanced use-case for pagination is **nested pagination.** This is when pagination is combined with other dynamic route params. You can use nested pagination to group your paginated collection by some property or tag.
@@ -90,7 +89,7 @@ Nested pagination works by returning an array of `paginate()` results from `getS
---
// Example: /src/pages/[tag]/[page].astro
export function getStaticPaths({paginate}) {
- const allTags = ['red', 'blue', 'green'];
+ const allTags = ['red', 'blue', 'green'];
const allPosts = Astro.fetchContent('../../posts/*.md');
// For every tag, return a paginate() result.
// Make sure that you pass `{params: {tag}}` to `paginate()`
diff --git a/packages/astro/src/build/page.ts b/packages/astro/src/build/page.ts
index dabf69175..e12f6ddac 100644
--- a/packages/astro/src/build/page.ts
+++ b/packages/astro/src/build/page.ts
@@ -32,10 +32,12 @@ export async function getStaticPathsForPage({
const mod = await snowpackRuntime.importModule(location.snowpackURL);
validateGetStaticPathsModule(mod);
const [rssFunction, rssResult] = generateRssFunction(astroConfig.buildOptions.site, route);
- const staticPaths: GetStaticPathsResult = await mod.exports.getStaticPaths({
- paginate: generatePaginateFunction(route),
- rss: rssFunction,
- }).flat();
+ const staticPaths: GetStaticPathsResult = await mod.exports
+ .getStaticPaths({
+ paginate: generatePaginateFunction(route),
+ rss: rssFunction,
+ })
+ .flat();
validateGetStaticPathsResult(staticPaths, logging);
return {
paths: staticPaths.map((staticPath) => staticPath.params && route.generate(staticPath.params)).filter(Boolean),
diff --git a/packages/astro/src/build/paginate.ts b/packages/astro/src/build/paginate.ts
index 87f58b605..21a7ba94f 100644
--- a/packages/astro/src/build/paginate.ts
+++ b/packages/astro/src/build/paginate.ts
@@ -10,9 +10,8 @@ import { GetStaticPathsResult, Params, Props, RouteData } from '../@types/astro'
// });
// });
-
export function generatePaginateFunction(routeMatch: RouteData) {
- return function paginateUtility(data: any[], args: { pageSize?: number, params?: Params, props?: Props } = {}) {
+ return function paginateUtility(data: any[], args: { pageSize?: number; params?: Params; props?: Props } = {}) {
let { pageSize: _pageSize, params: _params, props: _props } = args;
const pageSize = _pageSize || 10;
const paramName = 'page';
diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts
index ac63ce884..3a63775d7 100644
--- a/packages/astro/src/runtime.ts
+++ b/packages/astro/src/runtime.ts
@@ -130,12 +130,14 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
validateGetStaticPathsModule(mod);
cachedStaticPaths[routeMatch.component] =
cachedStaticPaths[routeMatch.component] ||
- (await mod.exports.getStaticPaths({
- paginate: generatePaginateFunction(routeMatch),
- rss: () => {
- /* noop */
- },
- })).flat();
+ (
+ await mod.exports.getStaticPaths({
+ paginate: generatePaginateFunction(routeMatch),
+ rss: () => {
+ /* noop */
+ },
+ })
+ ).flat();
validateGetStaticPathsResult(cachedStaticPaths[routeMatch.component], logging);
const routePathParams: GetStaticPathsResult = cachedStaticPaths[routeMatch.component];
diff --git a/packages/astro/test/astro-pagination.test.js b/packages/astro/test/astro-pagination.test.js
index e10e233a6..f58c482e6 100644
--- a/packages/astro/test/astro-pagination.test.js
+++ b/packages/astro/test/astro-pagination.test.js
@@ -45,7 +45,6 @@ Global('multiple params', async (context) => {
assert.equal($('#page-a').text(), '1');
assert.equal($('#page-b').text(), '1');
assert.equal($('#filter').text(), 'red');
-
}
{
const result = await context.runtime.load('/posts/blue/1');