Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
feat(postlist): Tag functionality with total count
Browse files Browse the repository at this point in the history
  • Loading branch information
y0nei committed May 16, 2023
1 parent d6c1fb1 commit 6bab98d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions posts/1/content.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
title: My first article
description: This is a description of my post.
tags: webdev
privacy
python
backend
date: 02-02-2023
---
This is the content of my **first** post
Expand Down
2 changes: 2 additions & 0 deletions posts/3/content.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: My third article
description: This is a description of my post.
tags: gardening
privacy
date: 02-02-2023
---
This is the content of my **third** post
6 changes: 5 additions & 1 deletion src/routes/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async def post_list(
hx_request: str | None = Header(None)
):
posts = []
taglist = []

def getPost(post_id: int):
try:
Expand All @@ -39,6 +40,8 @@ def getPost(post_id: int):
try:
post_id = int(post_id)
post = getPost(post_id)
if post.get("tags"):
[taglist.append(tag) for tag in post["tags"] if tag not in taglist]
posts.append(post)
except ValueError:
pass
Expand Down Expand Up @@ -76,7 +79,8 @@ def getPost(post_id: int):
"total_pages": total_pages,
"current_page": page,
"total": len(posts),
"pagination": pagination
"pagination": pagination,
"tags": taglist
}

if hx_request:
Expand Down

0 comments on commit 6bab98d

Please sign in to comment.