8 lines
1003 B
TypeScript
8 lines
1003 B
TypeScript
import type {GetServerSideProps} from 'next';
|
||
import Head from 'next/head';
|
||
import {Shell} from '@/components/Shell';
|
||
import {ExploreFeed} from '@/components/ExploreFeed';
|
||
import {exploreFeed,staticEntries,type ExploreEntry} from '@/lib/explore';
|
||
export default function Home({entries,cursor,q,total,unavailable=false}:{entries:ExploreEntry[];cursor:string|null;q:string;total?:number;unavailable?:boolean}){return <Shell><Head><title>PROMPT · 发现</title></Head>{unavailable&&<p role="status">素材库暂时无法连接,先看看这些公开笔记。</p>}<ExploreFeed key={q} initial={entries} cursor={cursor} q={q} total={total}/></Shell>}
|
||
export const getServerSideProps:GetServerSideProps=async({query})=>{const q=String(query.q||'').slice(0,200);try{const data=await exploreFeed(q);return {props:{entries:data.entries,cursor:data.nextCursor,total:data.total,q}}}catch{return {props:{entries:staticEntries.filter(e=>!q||(e.title+e.description).includes(q)),cursor:null,q,unavailable:true}}}};
|