0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

[ci] yarn format

This commit is contained in:
FredKSchott 2021-08-11 22:05:17 +00:00 committed by GitHub Actions
parent 0f0cc2b9d8
commit b63960f514
6 changed files with 17 additions and 18 deletions

View file

@ -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:

View file

@ -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.

View file

@ -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({
const staticPaths: GetStaticPathsResult = await mod.exports
.getStaticPaths({
paginate: generatePaginateFunction(route),
rss: rssFunction,
}).flat();
})
.flat();
validateGetStaticPathsResult(staticPaths, logging);
return {
paths: staticPaths.map((staticPath) => staticPath.params && route.generate(staticPath.params)).filter(Boolean),

View file

@ -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';

View file

@ -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({
(
await mod.exports.getStaticPaths({
paginate: generatePaginateFunction(routeMatch),
rss: () => {
/* noop */
},
})).flat();
})
).flat();
validateGetStaticPathsResult(cachedStaticPaths[routeMatch.component], logging);
const routePathParams: GetStaticPathsResult = cachedStaticPaths[routeMatch.component];

View file

@ -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');