Skip to content

Commit ec5ef06

Browse files
committed
feat: add real pagination for translations endpoint and remove the poor-mans pager
Closes #3
1 parent 3b3739e commit ec5ef06

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

api.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Kirby\Filesystem\Dir;
55
use Kirby\Filesystem\F;
66
use Kirby\Http\Response;
7+
use Kirby\Toolkit\Collection;
78

89
$contentRoot = kirby()->root('content');
910
$path = $contentRoot.DS.'localizer';
@@ -59,5 +60,25 @@
5960
return Response::json($translations);
6061
},
6162
],
63+
[
64+
'pattern' => '/localizer/translations/(:alpha)',
65+
'method' => 'get',
66+
'action' => function ($code) {
67+
$page = get('page', 1);
68+
$limit = get('limit', 10);
69+
$translations = kirby()->translations()->find($code ?? 'en');
70+
$collection = new Collection($translations->data());
71+
72+
$pagedCollection = $collection->paginate([
73+
'page' => $page,
74+
'limit' => $limit,
75+
]);
76+
77+
return Response::json([
78+
'data' => $pagedCollection->toArray(),
79+
'pagination' => $pagedCollection->pagination()->toArray(),
80+
]);
81+
},
82+
],
6283
],
6384
];

index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)