picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

limit prev/next_page to specific content/dir #634

Closed digitalinferno closed 2 years ago

digitalinferno commented 2 years ago

When we use the next_page / prev_page code it returns the next/prev page as specified by the config.yml configuration file If we have

content/blog
- page a
- page c
content/foo
- page b

then the alpha order is

- blog/page a
- foo/page b
- blog/page c

But for me it make no sense to have this order if I would navigate only the blog content (similar issue if we use the date sort).

So another level of configuration is needed, my 2 cents. pages_order_by: meta/alpha/date/subdir

In twig is something like this:

            {% set next_this = '' %}
            {% set prev_this = '' %}
            {% set n = '' %}
            {% set p = '' %}

            {% for page in pages(mysubdir)|sort_by(date)|reverse %}
                {% if current_page.id == page.id %}
                    {% set n = (loop.index-1) %}
                    {% set p = (loop.index+1) %}
                {% endif %}
            {% endfor %}   

            {% for page in pages(mysubdir)|sort_by(date)|reverse %}
                {% if n == loop.index %}
                    {% set next_this = page %}
                {% endif %}
                {% if p == loop.index %}
                    {% set prev_this = page %}
                {% endif %}  
            {% endfor %} 

            «{{ next_this.title}} ... {{ prev_this.title}}»
digitalinferno commented 2 years ago

@PhrozenByte it is an improvement request rather than a support request

PhrozenByte commented 2 years ago

Alpha order is going to be blog/page a, blog/page c and foo/page b, as pages aren't just sorted by their basename, but the full path. If you want it to roll over at the directory boundary, use the pages() function and sort_by filter (as you did, even though you don't need two iterations). pages_order is for the global page order. Directories don't have any special meaning in Pico on purpose, as we want users to organize their pages how they prefer.

See #615 for an extensive discussion about this and various Twig snippets

digitalinferno commented 2 years ago

Thank you, I have totally missed this discussion.