3.1 KB
blog.html
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
    {{partial "head"}}
    <title>Blog - {{site_name}}</title>
</head>
<body class="min-h-screen bg-base-200 flex flex-col">
    {{partial "header"}}
    <main class="container mx-auto p-8 flex-1">
        <div class="flex justify-between items-center mb-8">
            <div>
                <h1 class="text-4xl font-bold">Blog</h1>
                <p class="text-base-content/70 mt-2">Latest posts and updates</p>
            </div>
{{if .current_user}}
            <a href="/blog-new" class="btn btn-primary">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
                </svg>
                New Post
            </a>
            {{end}}
        </div>

        {{with $posts := documents "blog_posts" "ORDER BY CreatedAt DESC"}}
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            {{range $post := $posts}}
            <div class="card bg-base-100 shadow-xl hover:shadow-2xl transition-shadow">
                <div class="card-body">
                    {{if $post.GetBool "featured"}}
                    <div class="badge badge-primary mb-2">Featured</div>
                    {{end}}
                    <h2 class="card-title">{{$post.GetString "title"}}</h2>
                    <p class="text-base-content/70">{{$post.GetString "excerpt"}}</p>
                    <div class="flex items-center gap-2 text-sm text-base-content/50 mt-2">
                        <span>{{$post.GetString "author"}}</span>
                        {{with $t := $post.GetTime "publishedAt"}}
                        {{if not $t.IsZero}}
                        <span>&middot;</span>
                        <span>{{$t.Format "Jan 2, 2006"}}</span>
                        {{end}}
                        {{end}}
                    </div>
                    <div class="card-actions justify-end mt-4">
                        <a href="/blog-view?id={{$post.ID}}" class="btn btn-primary btn-sm">Read More</a>
                    </div>
                </div>
            </div>
            {{end}}
        </div>
        {{else}}
        <div class="flex flex-col items-center justify-center py-16 text-center">
            <div class="text-6xl mb-4 opacity-20">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-24 w-24 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9.5a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
                </svg>
            </div>
            <h3 class="text-xl font-semibold mb-2">No posts yet</h3>
            <p class="text-base-content/60 mb-6">Get started by creating your first blog post.</p>
            <a href="/blog-new" class="btn btn-primary">Create First Post</a>
        </div>
        {{end}}
    </main>
    {{partial "footer"}}
</body>
</html>
← Back