import { Breadcrumb } from '@/components/Breadcrumb' import { MetaHead } from '@/components/MetaHead' import { Sidebar } from '@/components/Sidebar' import { SidebarContentList } from '@/types/content-types' import { SearchResult } from '@/types/search-types' import { getSidebarContentList } from '@/utils/getSidebarContentList' import { GetServerSideProps } from 'next' import { useTheme } from 'next-themes' import Link from 'next/link' type Props = { sidebar: SidebarContentList results: SearchResult[] query: string } export default function SectionListPage({ sidebar, query, results }: Props) { const theme = useTheme() return ( <>

{`Found ${results.length} Results for "${query}"`}

    {results.map((result) => (
  • {result.subtitle}

    {result.title}

  • ))}
) } export const getServerSideProps: GetServerSideProps = async (ctx) => { // get the q out of search-results?q=foo const query = ctx.query?.q?.toString() as string if (!query) throw Error() const sidebar = await getSidebarContentList({}) // fetch from our current server const res = await fetch(`http://${ctx.req.headers.host}/api/search?q=${query}`) const json = await res.json() const results = json.results return { props: { sidebar, query, results } } }