{p.content}import Link from "next/link"; import { db } from "@/lib/db"; import { Attachments } from "./components/attachments";
export const dynamic = "force-dynamic";
type Post = { id:number; content:string; tags_json:string; attachments_json:string; created_at:string; username:string; name:string|null; source_base_url:string|null; comment_count:number; reaction_count:number };
export default async function Home({ searchParams }: { searchParams: Promise<{ q?: string; tag?: string }> }) {
const query = await searchParams;
const q = query.q?.trim() || ""; const tag = query.tag?.trim() || "";
const where = ["p.visibility = 'PUBLIC'", "p.hidden = 0"]; const args: string[] = [];
if (q) { where.push("p.content LIKE ?"); args.push(`%${q}%`); } if (tag) { where.push("p.tags_json LIKE ?"); args.push(`%${JSON.stringify(tag).slice(1,-1)}%`); }
const posts = db.prepare(`SELECT p.*, u.username, s.name, s.base_url AS source_base_url, (SELECT count(*) FROM comments c WHERE c.post_id=p.id AND c.hidden=0) comment_count, (SELECT count(*) FROM reactions r WHERE r.post_id=p.id) reaction_count FROM posts p JOIN users u ON u.id=p.author_id LEFT JOIN sources s ON s.id=p.source_id WHERE ${where.join(" AND ")} ORDER BY COALESCE(p.remote_created_at,p.created_at) DESC LIMIT 100`).all(...args) as Post[];
return <> 聚合朋友們公開分享的筆記。公開 Memos Hub
{p.content}尚無符合的公開貼文。
}>; }