nextcloud / cms_pico

🗃 Integrate Pico CMS and let your users manage their own websites
https://apps.nextcloud.com/apps/cms_pico
GNU Affero General Public License v3.0
137 stars 43 forks source link

next_page misses last element in folder #173

Closed margohl closed 3 years ago

margohl commented 3 years ago

Hi,

thank you for your awesome work! I have an issue with the functionality of "next_page".

I am building my own theme for PicoCMS on Nexcloud, and learning how it works at the same time, so I am rather inexperienced. The website holds a number of related entries that I want my reader to navigate through, with the next_page and previous_page functions.

assume my content structure as something like this

Main---
           |--A
                |--1
                |--2
                |--3
          |--B
                |--1
                |--2
                |--3
                ...
                |--n
          |--C
                |--1

I would expect that if i look at A2 it shows me A1 as previous page and A3 as next page. Yet, what actually happens, is that it does show me A1 as previous page, but C1 as next page, skipping A3.

If i look at A3, it links to nothing instead of A2 as previous page and to B1 as next page.

To generalize, Page (n-1) links to the first page in another folder for the next page, and to its actual previous page as such. Whereas page (n) links to nothing as previous page, and yet another first page in another folder as next page.

I would very much like to understand what the reason of that behavior is, and whether there is satisfying way of solving this (currently considering dummy pages, that do not show up to the users, as ugly work around)

On a sidenode: how is it determined which folder is chosen by next_page if the last page is reached, as the same starting folder links into two different other folders.

Thank you, MG

PhrozenByte commented 3 years ago

Works for me:

                iterate:<br>
                {% set page = pages["test/A/1"] %}
                {% for i in range(0, 10) %}
                    current = {{ page.id }} # next = {{ page.next_page.id }} # prev = {{ page.previous_page.id }}<br>
                    {% set page = page.next_page %}
                {% endfor %}

gives me

iterate:
current = test/A/1 # next = test/A/2 # prev = sub/page
current = test/A/2 # next = test/A/3 # prev = test/A/1
current = test/A/3 # next = test/B/1 # prev = test/A/2
current = test/B/1 # next = test/B/2 # prev = test/A/3
current = test/B/2 # next = test/B/3 # prev = test/B/1
current = test/B/3 # next = test/C/1 # prev = test/B/2
current = test/C/1 # next = # prev = test/B/3
current = # next = # prev =
current = # next = # prev =
current = # next = # prev =
current = # next = # prev = 

Pico sorts pages alphabetically by default.

Do you have any custom plugins? A lot of plugins change the page order - and often fail, because sorting a page tree is not that easy.

margohl commented 3 years ago

Hi! Thank you for your answer! unfortunately i can not seem to get it work based on it. My page is basically a mostly optically altered version of the "default theme", meaning no plugins enabled, and no java script, just pure css and pico, Nextcloud and Pico App on the latest (stable) version.

Here is the code i use:


{% for page in pages(current_page.id, offset=-1) %} 
                {% for nextparent  in pages(next_page.id, offset=-1) %}         
                    {% if nextparent.id == page.id %}
                    <h3>Nächster Eintrag</h3> 
                    <hr class="lineBNav">
                    <h1><a style="color:#000000;" href="{{ next_page.url }}">{{ next_page.title  }} </a></h1>
                    {% endif %}
                {% endfor %}
            {%endfor%}

The logic around it, basically just avoids showing entries from other folders. But even without this, <h1><a style="color:#000000;" href="{{ next_page.url }}">{{ next_page.title }} </a></h1> keeps missing the last page.

based on your code above i tried current_page.next_page.url to see if that might be part of the issue, but the issue persists.

One thing to note though is, that my pages are not ordered alphabetically, but it appears to me that they are sorted by last edited or created (i did not touch that), sorry to keep bothering you with this, Is this the right place for this?

PhrozenByte commented 3 years ago

I don't really understand what you're trying to do. Can you please elaborate what exactly you're trying to achieve?

margohl commented 3 years ago

Well essentially i want next_page to navigate to the next page... yet what actually happens is, if i use the above code, that the last page of any folder is skipped by the next_page function: Nav

the above image is how it looks in action, except that on the second to last page, the last page is not displayed as next page.

besides that i actually only want my page to show the next page within the current pages folder. which is what the long code example does (most likely not in the most elegant way)

PhrozenByte commented 3 years ago

What is supposed to happen if there's no next page in the current pages folder? Yield nothing?

margohl commented 3 years ago

If there is no next page in the folder, nothing is displayed on the right, and vice versa, if there is no previous page, nothing is displayed on the left. That is intended.

My problem is that, if i have n pages in a folder, on page n-1 next_page will not link to page n, and on page n, previous_page will not link to page n-1. Or as in the example of the original question. Of 3 pages, on page 2 next_page does not link to page 3. without my restrictions in the code above in place, page 2 links to another folders first page instead. And Page 3 does not link to page 2 with "previous_page" I just do not understand why the last page does not seem to be linked to its folder neighbours?

PhrozenByte commented 3 years ago

Try this (with your HTML) instead:

                {% if current_page.id|split('/')|slice(0, -1) == next_page.id|split('/')|slice(0, -1) %}
                    next: {{ next_page.id }}<br>
                {% else %}
                    next: ~none~<br>
                {% endif %}
                {% if current_page.id|split('/')|slice(0, -1) == previous_page.id|split('/')|slice(0, -1) %}
                    prev: {{ previous_page.id }}<br>
                {% else %}
                    prev: ~none~<br>
                {% endif %}
margohl commented 3 years ago

thank you for the code! it looks much cleaner. But my issue persists... In the attached image, you can see the index page, which lists all entries in its folder just fine. The previous / next page follows exactly that order, but then the second to last page ignores the last page and the last page claims it has no neighbors in its folder. next_page I have this issue in all my folders... so it is not just that one.

I kept my old code for now in the layoutet part and added yours unaltered as a quick test below ...

I would really like to understand why...

PhrozenByte commented 3 years ago

I would really like to understand why...

Dito :laughing: I thought it might be caused by your code, but this doesn't seem to be the case.

Did you try disabling all plugins?

Please also check the pages_order_by config in your data/appdata_*/cms_pico/config/config.yml. It should be alpha.

margohl commented 3 years ago

So the issue is solved... the sorting order was set to "date" by 2019-me

This is on me. In the summer of 2019 i had a first attempt with Pico on nextcloud. I played around with a theme i didn't build myself, but then gave up, because i had some unsolvable issues with the software... at that time around, i must have set the sorting order to "date" and now 2 years later of course i had forgotten about ever touching any configs.

I apologize for wasting your time.

Just two more questions: 1) how come that the sorting mode leads to such a behavior?

2) As sorting by date was actually pretty convenient for me... will there be a fix for the bug at some point?

Thanks again...

PhrozenByte commented 3 years ago

If you tell Pico to sort pages by date, it will sort pages by date. This is intended behaviour, no bugs here. One can still sort pages differently, simply try Pico's sort_by Twig filter.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: