from ...blog.ghost_db import DBClient # adjust import path from sqlalchemy import select from models.ghost_content import PostLike from quart import g async def post_data(slug, session, include_drafts=False): client = DBClient(session) posts = (await client.posts_by_slug(slug, include_drafts=include_drafts)) if not posts: # 404 page (you can make a template for this if you want) return None post, original_post = posts[0] # Check if current user has liked this post is_liked = False if g.user: liked_record = await session.scalar( select(PostLike).where( PostLike.user_id == g.user.id, PostLike.post_id == post["id"], PostLike.deleted_at.is_(None), ) ) is_liked = liked_record is not None # Add is_liked to post dict post["is_liked"] = is_liked tags=await client.list_tags( limit=50000 ) # <-- new authors=await client.list_authors( limit=50000 ) return { "post": post, "original_post": original_post, "tags": tags, "authors": authors, }