Instanssi / Instanssi.org

Website source
http://instanssi.org/
MIT License
7 stars 7 forks source link

Blog pagination #346

Open jpot opened 6 months ago

jpot commented 6 months ago

Initial version of the blog pagination. This uses a GET parameter "p" for page number (like https://instanssi.org/2024/?p=2 if there are over 10 blog entries)

This gets the basic job of pagination done.

pagination-screenshot

URLs to individual blog entries to be fixed in the future:

Linking to individual blog entry with its id on the URL (like https://instanssi.org/2024/#1) is not very good. If the blog entry is later on another page (because newer entries are added and it falls to another page) then old enough URLs (in social media) will become non-functional when the element with the certain id (1 in this example) does not exist on the first page (default) anymore.

We will need to address this case of linking to an individual blog entry separately with a different view. Then just link to that view's URL instead of using the HTML element id in the URL and the problem goes away.

Another option to fix the case would be to invert the page numbering so the first 10 ids would always be on page nr 1 and not the latest 10 on page nr 1. Then the default page would be whatever was the highest page number. Also the initial page load would need to set the p GET parameter correctly for links to entries to work also in the future (the user would copy the whole thing like ?p=1#1 from the address bar). However, most likely the first option is still the best and the most logical solution to use in here. We will want to have that "read a single blog post" view anyway.

katajakasa commented 6 months ago

Btw, to navigate to specific post, you could do something like ?pageWith= and then just load from database the count of posts where event matches the instanssi event id, and ID is smaller than or equal to the currently searched blog post. That would give you the count of posts before the post yo want to show, and you could count the page from that. Then you could just browse to correct page and highlight the post.

count = BlogPost.objects.filter(event=event_id).filter(pk__lte=pageWith).count()
page = floor(count / pageSize)
...