xy2z / capro

PHP8 static site generator
MIT License
8 stars 2 forks source link

Support for pagination #34

Open maharjanmilan opened 6 months ago

maharjanmilan commented 6 months ago

I was looking at this project and it looks really interesting for me being a Laravel developer previously. I didn't saw this in the documentation but was curious if it supported pagination for collection pages?

xy2z commented 6 months ago

A pagination like showing pages 1-100 is currently not a build in feature. It can be done using view templates - it's not pretty but possible. So I'd rather make a real pagination :)

If you only want to show next/prev pages, it can be done using the Capro class, here's an example of doing it for the capro docs site:

{{-- Next/prev pages --}}
<div class="pagination">
    {{-- Prev Page --}}
    @php ($prev_page = Capro::pages()->where('in_nav', true)->orderBy('nav_sort')->whereBetween('nav_sort', 0, $self->nav_sort-1)->last())
    @if ($prev_page)
        <a href="{{ $prev_page->href }}">
            <i class="fa-solid fa-chevron-left"></i>
            {{ $prev_page->title }}
        </a>
    @endif

    {{-- Next Page --}}
    @php ($next_page = Capro::pages()->where('in_nav', true)->orderBy('nav_sort')->whereBetween('nav_sort', $self->nav_sort+1, PHP_INT_MAX)->first())
    @if ($next_page)
        <a href="{{ $next_page->href }}" class="_right">
            {{ $next_page->title }}
            <i class="fa-solid fa-chevron-right"></i>
        </a>
    @endif
</div>

Also not super pretty, will probably find a nicer solution at some point.

maharjanmilan commented 6 months ago

thanks 👍