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

Commit 6bab98d

Browse files
committed
feat(postlist): Tag functionality with total count
1 parent d6c1fb1 commit 6bab98d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

posts/1/content.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
22
title: My first article
33
description: This is a description of my post.
4+
tags: webdev
5+
privacy
6+
python
7+
backend
48
date: 02-02-2023
59
---
610
This is the content of my **first** post

posts/3/content.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
title: My third article
33
description: This is a description of my post.
4+
tags: gardening
5+
privacy
46
date: 02-02-2023
57
---
68
This is the content of my **third** post

src/routes/posts.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async def post_list(
2424
hx_request: str | None = Header(None)
2525
):
2626
posts = []
27+
taglist = []
2728

2829
def getPost(post_id: int):
2930
try:
@@ -39,6 +40,8 @@ def getPost(post_id: int):
3940
try:
4041
post_id = int(post_id)
4142
post = getPost(post_id)
43+
if post.get("tags"):
44+
[taglist.append(tag) for tag in post["tags"] if tag not in taglist]
4245
posts.append(post)
4346
except ValueError:
4447
pass
@@ -76,7 +79,8 @@ def getPost(post_id: int):
7679
"total_pages": total_pages,
7780
"current_page": page,
7881
"total": len(posts),
79-
"pagination": pagination
82+
"pagination": pagination,
83+
"tags": taglist
8084
}
8185

8286
if hx_request:

0 commit comments

Comments
 (0)