import React from "react"; import { ArrowLeftIcon } from "@heroicons/react/24/outline"; import { formatDate, getAvailableSites, getResults } from "@/utils"; import SimplifiedSearchBar from "@/components/SimplifiedSearchBar"; import { Link, useLoaderData, useSearchParams } from "@remix-run/react"; import { json, LoaderFunction } from "@remix-run/node"; import type { SearchResult, SiteList } from "@/types.js"; import { generateMetaTags } from "@/lib/meta.js"; import type { ServerRuntimeMetaArgs } from "@remix-run/server-runtime"; type LoaderData = { sites: SiteList; results: SearchResult[]; query: string; }; export function meta(meta: ServerRuntimeMetaArgs) { const title = "Search - web3.news: Discover Community Web3 News"; const description = "Find the latest Web3, Crypto, and DeFi news easily with web3.news search. Dive into community-driven, cutting-edge content."; return [ ...generateMetaTags({ title: title, description: description, parentMeta: meta, }), ]; } export let loader: LoaderFunction = async ({ request }) => { const sites = getAvailableSites(); const search = new URL(request.url).searchParams; const query = search.get("q") ?? ""; const site = search.get("site") ?? undefined; const time = search.get("time") ?? undefined; const results = await getResults({ query: query, site, time }); // Return the fetched data as JSON return json({ sites, results, query }); }; const Page = () => { const { sites, results, query } = useLoaderData(); return (
{results.length > 0 && ( <> {results.map((item) => ( {formatDate(item.timestamp)}

{" "} {item.title}

))} )}
); }; export default Page;