
commit e1f0eeefefafe73e6903ae52b4359ca438018078 Author: HackerNCoder <hackerncoder@encryptionin.space> Date: Mon Aug 30 17:16:19 2021 +0000 Fix #75: Coverage list is too long --- models/press.ini | 1 + templates/macros/pagination.html | 68 ++++++++++++++++++++++++++++++++++++++++ templates/press.html | 8 ++++- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/models/press.ini b/models/press.ini index 3757f1bd..0f30beaa 100644 --- a/models/press.ini +++ b/models/press.ini @@ -35,3 +35,4 @@ slug_format = {{ ((this.pub_date) if this.pub_date) ~ "-" ~ this._id }} [pagination] enabled = yes per_page = 10 +items = site.query('/press').include_undiscoverable(true).filter(F.type == "snippet") diff --git a/templates/macros/pagination.html b/templates/macros/pagination.html new file mode 100644 index 00000000..2aa681b7 --- /dev/null +++ b/templates/macros/pagination.html @@ -0,0 +1,68 @@ +{% macro render_pagination(pagination, year, oldest) %} + <nav aria-label="page navigation"> + <ul class="pagination"> + {% if pagination.has_prev %} + <li class="page-item"><a class="page-link" href="{{ pagination.prev|url }}">Newer</a></li> + {% else %} + <li class="page-item disabled"><a class="page-link" href="">Newer</a></li> + {% endif %} + + {% if pagination.has_prev %} + {% if pagination.for_page(pagination.page-2).has_prev %} + {% set goback = 2 %} + {% else %} + {% set goback = 1 %} + {% endif %} + + {% if pagination.has_next %} + {% if pagination.for_page(pagination.page+2).has_next %} + {% set goforw = 3 %} + {% else %} + {% set goforw = 2 %} + {% endif %} + + {% for i in range(pagination.page-goback, pagination.page+goforw)%} + {% set yearToShow = year-(i-pagination.page) %} + {% if yearToShow >= oldest %} + {% if i == pagination.page %} + <li class="page-item active"><a class="page-link" href="{{ pagination.for_page(i)|url }}">{{ yearToShow }}</a></li> + {% else %} + <li class="page-item"><a class="page-link" href="{{ pagination.for_page(i)|url }}">{{ yearToShow }}</a></li> + {% endif %} + {% endif %} + {% endfor %} + + {% else %} + {% for i in range(pagination.page-5, pagination.page)%} + {% set yearToShow = year-(i-pagination.page+1) %} + {% if yearToShow >= oldest %} + {% if i == pagination.page %} + <li class="page-item active"><a class="page-link" href="{{ pagination.for_page(i)|url }}">{{ yearToShow }}</a></li> + {% else %} + <li class="page-item"><a class="page-link" href="{{ pagination.for_page(i)|url }}"> {{ yearToShow }}</a></li> + {% endif %} + {% endif %} + {% endfor %} + {% endif %} + + {% else %} + {% for i in range(pagination.page, pagination.page+5)%} + {% set yearToShow = year-(i-1) %} + {% if yearToShow >= oldest %} + {% if i == pagination.page %} + <li class="page-item active"><a class="page-link" href="{{ pagination.for_page(i)|url }}"> {{ yearToShow }}</a></li> + {% else %} + <li class="page-item"><a class="page-link" href="{{ pagination.for_page(i)|url }}"> {{ yearToShow }}</a></li> + {% endif %} + {% endif %} + {% endfor %} + {% endif%} + + {% if pagination.has_next %} + <li class="page-item"><a class="page-link" href="{{ pagination.next|url }}">Older</a></li> + {% else %} + <li class="page-item disabled"><a class="page-link" href="">Older</a></li> + {% endif %} + </ul> + </nav> +{% endmacro %} diff --git a/templates/press.html b/templates/press.html index d63b46cb..2ea49a82 100644 --- a/templates/press.html +++ b/templates/press.html @@ -47,10 +47,16 @@ </tr> </thead> <tbody> + {% from "macros/pagination.html" import render_pagination %} {% from "macros/press.html" import render_snippet %} {% set items = site.query('/press').include_undiscoverable(true).filter(F.type == "snippet") %} + {% set year = items.first().pub_date.year-(this.pagination.page-1) %} + {% set oldest = items.all()|last %} + {{ render_pagination(this.pagination, year, oldest.pub_date.year) }} {% for item in items %} - {{ render_snippet(item, this.alt) }} + {% if item.pub_date.year == year %} + {{ render_snippet(item, this.alt) }} + {% endif %} {% endfor %} </tbody> </table>