async def tag(request: Request, tag_id: int, page: int = 0): items_per_page = 3 posts = await fetch_posts_by_tag(tag_id, offset=page * items_per_page, limit=items_per_page) return templates.TemplateResponse( "tag_posts.html", get_context(request, tag_id=tag_id, posts=posts, page=page))
async def tags(request: Request): # TODO: tags page tags = await fetch_tags() return templates.TemplateResponse("tags.html", get_context(request, tags=tags))
async def post(request: Request, post_id: int): post = await fetch_post(post_id) context = get_context(request, post=post) return templates.TemplateResponse("post.html", context)
async def posts(request: Request, page: int = 0): items_per_page = 3 posts = await fetch_posts(offset=page * items_per_page, limit=items_per_page) context = get_context(request, posts=posts, page=page) return templates.TemplateResponse("posts.html", context)
async def index(request: Request): context = get_context(request, page=-1) return templates.TemplateResponse("home.html", context)
async def contact(request: Request): context = get_context(request) return templates.TemplateResponse("contact.html", context)
async def about(request: Request): context = get_context(request) return templates.TemplateResponse("about.html", context)
async def tag(request: Request, tag_id: int): tag = await fetch_tag(tag_id) return templates.TemplateResponse("tag.html", get_context(request, tag=tag, page=-1))