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(blog): add sorting, better rendering #1541

Merged
merged 33 commits into from
Feb 24, 2024

Conversation

leohhhn
Copy link
Contributor

@leohhhn leohhhn commented Jan 16, 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

New blog home page (sorted newest-top-left):
Screenshot 2024-01-23 at 11 33 38

Old post rendering - header & footer:
Screenshot 2024-01-23 at 11 34 46

New post rendering - header & footer:
Screenshot 2024-01-23 at 11 35 03

Screenshot 2024-01-23 at 11 35 11

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 of the gnoblog-cli tool.

Related: gnolang/blog#20

Contributors' checklist...
  • 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, if any. More info here.

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Jan 16, 2024
@leohhhn leohhhn changed the title feat(blog): add sorting by title & publication ate feat(blog): add sorting by title & publication date Jan 16, 2024
Copy link

codecov bot commented Jan 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 47.48%. Comparing base (16c7c2e) to head (60a5d61).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1541      +/-   ##
==========================================
+ Coverage   47.41%   47.48%   +0.06%     
==========================================
  Files         385      385              
  Lines       61319    61408      +89     
==========================================
+ Hits        29074    29159      +85     
+ Misses      29826    29812      -14     
- Partials     2419     2437      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the 📦 ⛰️ gno.land Issues or PRs gno.land package related label Jan 20, 2024
@leohhhn leohhhn changed the title feat(blog): add sorting by title & publication date feat(blog): add sorting, better rendering Jan 20, 2024
@leohhhn
Copy link
Contributor Author

leohhhn commented Jan 24, 2024

There is currently a bug in the rendering of the realm, specifically related to parsing time.Time. Putting this PR on hold until we figure out what is going on - it seems that it is a deeper issue than just the blog code.

Bug in question: #1588

The issue mainly happens when there is no date provided in the frontmatter of the blog post README, which is somethign that shouldn't really happen in our case, since there is a review process in place.

@leohhhn leohhhn marked this pull request as ready for review January 26, 2024 10:35
@leohhhn leohhhn requested review from moul and a team as code owners January 26, 2024 10:35
@leohhhn leohhhn removed request for a team and thehowl February 9, 2024 12:14
@leohhhn
Copy link
Contributor Author

leohhhn commented Feb 13, 2024

Currently cannot figure out why CI is failing - both examples lint & examples test fail because of the same reason:
gno test . --verbose at r/gnoland/pages displays a panic from the VM, even if the pages_test.gno file contains no tests. r/gnoland/blog tests pass fine.
Panic in question

Other than that, PR can be reviewed. It is supposed to be used in sync with the refactor of the gnoblog-cli.
This is the first in a series of PRs I have for making the blog better.

Edit: fixed in 4283930

@leohhhn leohhhn marked this pull request as ready for review February 13, 2024 21:26
@leohhhn leohhhn requested a review from moul February 13, 2024 22:42
examples/gno.land/p/demo/blog/blog.gno Outdated Show resolved Hide resolved
@thehowl
Copy link
Member

thehowl commented Feb 23, 2024

Suggest reverting the changes to Comment and then we should be good to merge

@leohhhn leohhhn merged commit 6f4efc6 into gnolang:master Feb 24, 2024
187 of 188 checks passed
@leohhhn leohhhn deleted the feat/blog-sort branch February 24, 2024 17:24
leohhhn added a commit to leohhhn/gno that referenced this pull request 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 <94029+moul@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Status: Done
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants