Skip to content

Commit

Permalink
feat: add real pagination for translations endpoint and remove the po…
Browse files Browse the repository at this point in the history
…or-mans pager

Closes #3
  • Loading branch information
gearsdigital committed Dec 1, 2021
1 parent 3b3739e commit ec5ef06
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
21 changes: 21 additions & 0 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Kirby\Filesystem\Dir;
use Kirby\Filesystem\F;
use Kirby\Http\Response;
use Kirby\Toolkit\Collection;

$contentRoot = kirby()->root('content');
$path = $contentRoot.DS.'localizer';
Expand Down Expand Up @@ -59,5 +60,25 @@
return Response::json($translations);
},
],
[
'pattern' => '/localizer/translations/(:alpha)',
'method' => 'get',
'action' => function ($code) {
$page = get('page', 1);
$limit = get('limit', 10);
$translations = kirby()->translations()->find($code ?? 'en');
$collection = new Collection($translations->data());

$pagedCollection = $collection->paginate([
'page' => $page,
'limit' => $limit,
]);

return Response::json([
'data' => $pagedCollection->toArray(),
'pagination' => $pagedCollection->pagination()->toArray(),
]);
},
],
],
];
2 changes: 1 addition & 1 deletion index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ec5ef06

Please sign in to comment.