import {previewUrl} from '@/content/page-links'; import {SkillCard} from "./SkillCard"; import {skillCatalog} from "@/content/skills/catalog"; import Head from "next/head"; import Link from "next/link"; import { useEffect,useRef,useState } from "react"; import { useRouter } from "next/router"; import { Search,Image as ImageIcon,ArrowUpRight,AudioLines,Film,Layers,ArrowDown,Upload } from "lucide-react"; import { Shell } from "./Shell"; import { sections,mediaUrl,type FeedData,type Post } from "@/lib/model"; export function PostCard({post}:{post:Post}){ const image=post.assets.find(a=>a.kind==='image');const video=post.assets.find(a=>a.kind==='video');const cover=post.cover_asset_id||image?.id; const label=sections.find(s=>s.kind===post.kind)?.name;const count=post.assets.filter(a=>a.kind!=='text').length; const source=cover?mediaUrl(cover):video?.variants.includes('poster')?mediaUrl(video.id,'poster'):null; return
{source?{post.title}:post.kind==='audio'?
{Array.from({length:36},(_,i)=>)}
:
{post.kind==='video'?:}{label}
} {count>1&&{count}}{video&&{video.has_audio?'有声音':'无声音'}}

{post.title}

{label}
; } function Masonry({posts,includeSkills=false,q=""}:{posts:Post[];includeSkills?:boolean;q?:string}){ const element=useRef(null);const [width,setWidth]=useState(1100); useEffect(()=>{if(!element.current)return;const observer=new ResizeObserver(entries=>setWidth(entries[0].contentRect.width));observer.observe(element.current);return ()=>observer.disconnect();},[]); const count=width>1250?5:width>1000?4:width>720?3:2; type Item={post?:Post;skill?:typeof skillCatalog[number];date:string};const columns:Item[][]=Array.from({length:count},()=>[]);const items:Item[]=[...posts.map(post=>({post,date:post.created_at})),...(includeSkills?skillCatalog.filter(s=>(s.title+s.description+s.category).toLowerCase().includes(q.toLowerCase())).map(skill=>({skill,date:skill.created_at})):[])].sort((a,b)=>b.date.localeCompare(a.date));const heights=Array(count).fill(0);const cardWidth=(width-(width<=720?14:20)*(count-1))/count; for(const item of items){const image=item.post?.assets.find(a=>a.kind==='image');const ratio=item.skill?1.25:image?.width&&image.height?image.height/image.width:item.post?.kind==='audio'?1:1.25;const index=heights.indexOf(Math.min(...heights));columns[index].push(item);heights[index]+=Math.min(cardWidth*ratio,item.skill?440:460)+78;} return
{columns.map((items,i)=>
{items.map(item=>item.skill?:)}
)}
; } export function Feed({initial,section='',tagPath=''}:{initial:FeedData;section?:string;tagPath?:string}){ const router=useRouter();const [posts,setPosts]=useState(initial.posts);const [cursor,setCursor]=useState(initial.nextCursor);const [busy,setBusy]=useState(false);const [error,setError]=useState('');const generation=useRef(0); useEffect(()=>{generation.current++;setPosts(initial.posts);setCursor(initial.nextCursor);setError('');setBusy(false);},[initial,router.query.q]); const current=sections.find(s=>s.path===section);const target=initial.tags.find(t=>t.path===tagPath);const children=initial.tags; async function load(){const gen=generation.current;setBusy(true);setError('');try{const q=new URLSearchParams({section,path:tagPath,cursor:cursor||'',q:String(router.query.q||'')});const res=await fetch('/api/feed?'+q);const d=await res.json();if(!res.ok)throw new Error(d.error);if(gen===generation.current){setPosts(old=>[...old,...d.posts.filter((p:Post)=>!old.some(a=>a.id===p.id))]);setCursor(d.nextCursor);}}catch{if(gen===generation.current)setError('加载没有完成,点击重试。');}finally{if(gen===generation.current)setBusy(false);}} return {target?.name||current?.name||'灵感首页'} · PROMPT {current&&

{target?.name||current.name}

{current.hint}

} {tagPath&&
全部{current?.name}{tagPath.split('/').map((_,i)=>{const path=tagPath.split('/').slice(0,i+1).join('/');return / {initial.tags.find(t=>t.path===path)?.name};})}
}
{!section?<>全部{sections.map(s=>{s.name})}:<>全部{children.map(t=>{t.name})}}
最近收录
{initial.unavailable?

素材库暂时没有连接上

请稍后刷新,已保存的内容不会因此丢失。

:(posts.length||(!section&&skillCatalog.some(s=>(s.title+s.description+s.category).toLowerCase().includes(String(router.query.q||'').toLowerCase()))))?:
A LITTLE SPACE FOR SOMETHING GOOD

{router.query.q?'还没有找到这份灵感':'这里还没有内容'}

{router.query.q?'换一个词试试看。':'导入图片、视频或声音,开始整理你的素材。'}

导入素材图文和动态作品通过代码加入,自由决定每一个像素。
} {cursor&&
}
; }