|
1 | 1 | --- |
2 | 2 | import Icon from '#src/astro/components/Icon.astro'; |
3 | 3 |
|
4 | | -const { pagination } = Astro.props; |
| 4 | +const { pagination, journey } = Astro.props; |
5 | 5 |
|
6 | | -if (!pagination) return null; |
| 6 | +if (!pagination && !journey) return null; |
7 | 7 |
|
8 | | -const { |
9 | | - pageNumber, |
10 | | - totalPages, |
11 | | - baseUrl, |
12 | | - hasPrevious, |
13 | | - hasNext, |
14 | | - totalItems, |
15 | | - itemType |
16 | | -} = pagination; |
| 8 | +const isJourney = Boolean(journey); |
17 | 9 |
|
18 | | -const previousUrl = `${baseUrl}/p/${hasPrevious ? pageNumber - 1 : 1}`; |
19 | | -const nextUrl = `${baseUrl}/p/${hasNext ? pageNumber + 1 : totalPages}`; |
| 10 | +const hasPrevious = isJourney ? Boolean(journey.previousUrl) : pagination.hasPrevious; |
| 11 | +const previousText = 'Previous'; |
| 12 | +const previousUrl = isJourney ? |
| 13 | + journey.previousUrl : |
| 14 | + `${pagination.baseUrl}/p/${hasPrevious ? pagination.pageNumber - 1 : 1}`; |
| 15 | +
|
| 16 | +const hasNext = isJourney ? Boolean(journey.nextUrl) : pagination.hasNext; |
| 17 | +const nextText ='Next'; |
| 18 | +const nextUrl = isJourney ? |
| 19 | + journey.nextUrl : |
| 20 | + `${pagination.baseUrl}/p/${hasNext ? pagination.pageNumber + 1 : pagination.totalPages}`; |
| 21 | +
|
| 22 | +const detail = isJourney ? |
| 23 | + `<a href="${journey.url}">${journey.title}</a> collection <span>(${journey.itemNumber} of ${journey.totalItems} articles)</span>` : |
| 24 | + `Page ${pagination.pageNumber} of ${pagination.totalPages} (${pagination.totalItems} ${pagination.itemType})`; |
20 | 25 | --- |
21 | 26 | <nav aria-label='Pagination'> |
22 | 27 | <a href={previousUrl} rel='prev' aria-disabled={!hasPrevious}> |
23 | 28 | <Icon name='chevron-left' size='1.25em' /> |
24 | | - Previous |
| 29 | + {previousText} |
25 | 30 | </a> |
26 | 31 | <a href={nextUrl} rel='next' aria-disabled={!hasNext}> |
27 | | - Next |
| 32 | + {nextText} |
28 | 33 | <Icon name='chevron-right' size='1.25em' /> |
29 | 34 | </a> |
30 | | - <p> |
31 | | - {`Page ${pageNumber} of ${totalPages} (${totalItems} ${itemType})`} |
32 | | - </p> |
| 35 | + <p set:html={detail} /> |
33 | 36 | </nav> |
0 commit comments