diff --git a/src/_data/feeds.ts b/src/_data/feeds.ts index 884bfe3..7c37959 100644 --- a/src/_data/feeds.ts +++ b/src/_data/feeds.ts @@ -10,6 +10,7 @@ const rssFeedUrls = [ "https://overreacted.io/rss.xml", "https://cassidoo.co/rss.xml", "https://waku.gg/api/rss.xml", + "https://blog.isquaredsoftware.com/index.xml", // from francois "https://francoisbest.com/posts/feed/rss.xml", diff --git a/src/components/search.tsx b/src/components/search.tsx index fcf7d50..a138822 100644 --- a/src/components/search.tsx +++ b/src/components/search.tsx @@ -7,14 +7,17 @@ import { SearchEngine, SearchResult } from "../_lib/search-engine"; import { useRouter_UNSTABLE } from "waku"; import { ListBox, ListBoxItem, Header, Text } from "react-aria-components"; -const fetchSearchIndex = async (): Promise => { +const fetchSearchIndex = async (): Promise<{ + engine: SearchEngine; + postCount: number; +}> => { const response = await fetch("/api/search.json"); if (!response.ok) { throw new Error("Failed to load search index"); } - const index = await response.json(); + const { index, postCount } = await response.json(); const engine = new SearchEngine(index); - return engine; + return { engine, postCount }; }; const ABC = "abcdefghijklmnopqrstuvwxyz"; @@ -29,7 +32,7 @@ export const Searcher = () => { const searchInputRef = useRef(null); const { - data: searchEngine, + data: search, isLoading, error, } = useQuery({ @@ -39,16 +42,16 @@ export const Searcher = () => { }); useEffect(() => { - if (!searchEngine || query === results.query) { + if (!search || query === results.query) { return; } else if (!query.trim()) { setResults({ results: [], query }); return; } - const searchResults = searchEngine.search(query, 25); + const searchResults = search.engine.search(query, 25); setResults({ results: searchResults, query }); - }, [query, searchEngine]); + }, [query, search]); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { @@ -98,7 +101,7 @@ export const Searcher = () => { />
{/* Search bar */} -
+
@@ -110,7 +113,7 @@ export const Searcher = () => { placeholder={ isLoading ? "Loading search index..." - : "Search RSS feeds... (Press '/' to focus)" + : `Search ${search?.postCount} posts...` } className="w-full py-4 pl-10 pr-4 text-lg border rounded-full shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" disabled={isLoading} diff --git a/src/pages/api/search.json.ts b/src/pages/api/search.json.ts index 26a6bf6..fa57a4a 100644 --- a/src/pages/api/search.json.ts +++ b/src/pages/api/search.json.ts @@ -219,12 +219,13 @@ export const GET = async () => { try { // Get the feed data const feeds = await getFeedData(); + const postCount = feeds.reduce((acc, cur) => acc + cur.items.length, 0); // Build the search index console.time("Building search index"); const searchIndex = buildSearchIndex(feeds); console.timeEnd("Building search index"); // Return the index as JSON - return Response.json(searchIndex); + return Response.json({ index: searchIndex, postCount }); } catch (error) { console.error("Error generating search index:", error); return new Response(