Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sort articles #20

Closed
moul opened this issue Apr 24, 2023 · 1 comment
Closed

feat: sort articles #20

moul opened this issue Apr 24, 2023 · 1 comment
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@moul
Copy link
Member

moul commented Apr 24, 2023

Currently, the display order of the blogposts appears random as it relies on the avl.Tree without any sorting mechanism.

To resolve this, we can either switch to a new format or, alternatively, maintain the avl.Tree for articles while introducing diverse methods to sort articles based on filters. The latter option could be more compelling.

Related code: https://github.com/gnolang/gno/tree/master/examples/gno.land/p/demo/blog

@moul moul added bug Something isn't working good first issue Good for newcomers labels Apr 24, 2023
@moul moul changed the title Fix display order in blogpost listing feat: sort articles Apr 24, 2023
@leohhhn leohhhn self-assigned this Oct 5, 2023
@leohhhn leohhhn moved this to Backlog in 👥 Team: Devrels Oct 11, 2023
@waymobetta waymobetta moved this from Backlog to In Progress in 👥 Team: Devrels Nov 20, 2023
@leohhhn leohhhn moved this from In Progress to In Review in 👥 Team: Devrels Nov 22, 2023
@leohhhn leohhhn moved this from In Review to Awaiting/Blocked in 👥 Team: Devrels Jan 25, 2024
@leohhhn leohhhn moved this from Awaiting/Blocked to In Review in 👥 Team: Devrels Jan 29, 2024
leohhhn added a commit to gnolang/gno that referenced this issue Feb 24, 2024
## Description

This PR adds two new AVL trees that enable sorting of the blog posts by
publication date and title.
This approach utilizes the fact that the AVL tree iteration order is
lexicographic by key. We introduce two new AVL trees into the `Blog`
struct - which store a key to sort by (title or publication date), and
store the pointers to posts, meaning the memory overhead is small.

This PR also modifies the rendering of the blog:

Old blog home page:
![Screenshot 2024-01-23 at 11 34
10](https://github.com/gnolang/gno/assets/33522493/78e197d3-a477-49a9-88d8-06b4f2c3d51d)

New blog home page (sorted newest-top-left):
![Screenshot 2024-01-23 at 11 33
38](https://github.com/gnolang/gno/assets/33522493/16712e37-c971-4cf5-9962-9dbf639a6088)

Old post rendering - header & footer:
![Screenshot 2024-01-23 at 11 34
46](https://github.com/gnolang/gno/assets/33522493/d6a713bb-379c-44b7-9ea7-38997e6b5c5a)

New post rendering - header & footer:
![Screenshot 2024-01-23 at 11 35
03](https://github.com/gnolang/gno/assets/33522493/352ea40d-c9ac-41a0-a362-fb3c5ca62968)
----
![Screenshot 2024-01-23 at 11 35
11](https://github.com/gnolang/gno/assets/33522493/6f21416c-8945-4eca-9bee-b67a9e56a568)


The API changes are the following:
- Each post now stores the publisher (ie caller of ModAddPost), and the
authors.
- It is envisioned that the author list will be a list of GitHub
usernames, while the publisher is simply the address of the caller. A PR
in the Blog repo will be added to accommodate this change.
- If the author list in the frontmatter of the blog post is empty, just
the publisher will be displayed
- The timestamp for when the blog was written will primarily be taken in
from the outside world, ie from the frontmatter, in the `RFC3339`
format. This timestamp allows us to still keep the ordering of the blogs
even when the block height/timestamp is unreliable. In case the
timestamps are not provided, time.Now() in the realm will be used
instead.

Publishing flow - two options:
- Pass in data directly to the blog realm via `ModAddPost`,
- Use the `gnoblog-cli` or similar parsing & publishing tool.
Either way, it is expected that any timestamps passed will be used in
the `time.RFC3339` format.

This PR is being published in pair with a
[refactor](gnolang/blog#63) of the gnoblog-cli
tool.

Related: gnolang/blog#20

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Manfred Touron <[email protected]>
leohhhn added a commit to leohhhn/gno that referenced this issue Feb 29, 2024
## Description

This PR adds two new AVL trees that enable sorting of the blog posts by
publication date and title.
This approach utilizes the fact that the AVL tree iteration order is
lexicographic by key. We introduce two new AVL trees into the `Blog`
struct - which store a key to sort by (title or publication date), and
store the pointers to posts, meaning the memory overhead is small.

This PR also modifies the rendering of the blog:

Old blog home page:
![Screenshot 2024-01-23 at 11 34
10](https://github.com/gnolang/gno/assets/33522493/78e197d3-a477-49a9-88d8-06b4f2c3d51d)

New blog home page (sorted newest-top-left):
![Screenshot 2024-01-23 at 11 33
38](https://github.com/gnolang/gno/assets/33522493/16712e37-c971-4cf5-9962-9dbf639a6088)

Old post rendering - header & footer:
![Screenshot 2024-01-23 at 11 34
46](https://github.com/gnolang/gno/assets/33522493/d6a713bb-379c-44b7-9ea7-38997e6b5c5a)

New post rendering - header & footer:
![Screenshot 2024-01-23 at 11 35
03](https://github.com/gnolang/gno/assets/33522493/352ea40d-c9ac-41a0-a362-fb3c5ca62968)
----
![Screenshot 2024-01-23 at 11 35
11](https://github.com/gnolang/gno/assets/33522493/6f21416c-8945-4eca-9bee-b67a9e56a568)


The API changes are the following:
- Each post now stores the publisher (ie caller of ModAddPost), and the
authors.
- It is envisioned that the author list will be a list of GitHub
usernames, while the publisher is simply the address of the caller. A PR
in the Blog repo will be added to accommodate this change.
- If the author list in the frontmatter of the blog post is empty, just
the publisher will be displayed
- The timestamp for when the blog was written will primarily be taken in
from the outside world, ie from the frontmatter, in the `RFC3339`
format. This timestamp allows us to still keep the ordering of the blogs
even when the block height/timestamp is unreliable. In case the
timestamps are not provided, time.Now() in the realm will be used
instead.

Publishing flow - two options:
- Pass in data directly to the blog realm via `ModAddPost`,
- Use the `gnoblog-cli` or similar parsing & publishing tool.
Either way, it is expected that any timestamps passed will be used in
the `time.RFC3339` format.

This PR is being published in pair with a
[refactor](gnolang/blog#63) of the gnoblog-cli
tool.

Related: gnolang/blog#20

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Manfred Touron <[email protected]>
@leohhhn
Copy link
Collaborator

leohhhn commented Mar 4, 2024

Closed by #64 & gnolang/gno#1541

@leohhhn leohhhn closed this as completed Mar 4, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in 👥 Team: Devrels Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants