Skip to content

Commit

Permalink
fix: disable pagination on json output if excluded
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Dec 22, 2023
1 parent 08c9d8f commit e5da52a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions config/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@
'extension' => 'xml',
'exclude' => ['redirect', 'paginated'],
],
// e.g.: blog/post-1.json
// e.g.: blog.json
-4 => [
'name' => 'json',
'mediatype' => 'application/json',
'extension' => 'json',
'exclude' => ['redirect'],
],
// e.g.: blog/post-1.xml
// e.g.: blog.xml
-5 => [
'name' => 'xml',
'mediatype' => 'application/xml',
Expand Down
2 changes: 1 addition & 1 deletion resources/layouts/_default/list.json.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- set pages = page.pages -%}
{% endif %}
{# in case of a paginated list page, take the paginator list pages #}
{% if page.paginator.pages is defined and paginator ?? true != false %}
{% if page.paginator.pages is defined and 'paginated' not in site.outputproperty('json', 'exclude') %}
{%- set pages = page.paginator.pages -%}
{% endif %}

Expand Down
4 changes: 2 additions & 2 deletions resources/layouts/_default/page.json.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]
{#- meta #}
{% block meta %}
{% if meta is not defined and (page.paginator.pages is defined and paginator ?? true != false) %}
{% if meta is not defined and (page.paginator.pages is defined and 'paginated' not in site.outputproperty('json', 'exclude')) %}
{% set meta = {'totalPages': page.paginator.totalpages} %}
{% endif %}
{% if meta is defined %},
Expand All @@ -24,7 +24,7 @@
{% endblock meta %}
{# links #}
{% block links %}
{% if links is not defined and (page.paginator.pages is defined and paginator ?? true != false) %}
{% if links is not defined and (page.paginator.pages is defined and 'paginated' not in site.outputproperty('json', 'exclude')) %}
{% set links = {
'self': url(page.paginator.links.self, {canonical: true, format: 'json'}),
'first': url(page.paginator.links.first, {canonical: true, format: 'json'}),
Expand Down
8 changes: 8 additions & 0 deletions src/Renderer/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,12 @@ public function getTime(): int
{
return time();
}

/**
* Returns the property value of an output format.
*/
public function getOutputProperty(string $name, string $property): string|array|null
{
return $this->config->getOutputFormatProperty($name, $property);
}
}

0 comments on commit e5da52a

Please sign in to comment.