mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-06 04:21:55 +00:00
chore: migrate unicorn profile pic mapping to Rollup plugin
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import type { VercelRequest, VercelResponse } from "@vercel/node";
|
||||
|
||||
import exportedIndex from "../searchIndex";
|
||||
import unicornProfilePicMap from "../public/unicorn-profile-pic-map";
|
||||
import Fuse from "fuse.js";
|
||||
import type { PostInfo } from "../src/types/PostInfo";
|
||||
|
||||
const myIndex = Fuse.parseIndex(exportedIndex.index);
|
||||
|
||||
@@ -18,11 +20,19 @@ const fuse = new Fuse(
|
||||
myIndex
|
||||
);
|
||||
|
||||
const unicornProfilePicObj = {};
|
||||
for (const picMapItem of unicornProfilePicMap) {
|
||||
unicornProfilePicObj[picMapItem.id] = picMapItem;
|
||||
}
|
||||
|
||||
export default async (req: VercelRequest, res: VercelResponse) => {
|
||||
// TODO: `pickdeep` only required fields
|
||||
const searchStr = req?.query?.query as string;
|
||||
if (!searchStr) return [];
|
||||
if (Array.isArray(searchStr)) return [];
|
||||
const items = fuse.search(searchStr).map((item) => item.item);
|
||||
res.send(items);
|
||||
const posts = fuse.search(searchStr).map((item) => item.item as PostInfo);
|
||||
const unicornProfilePicMap = posts.flatMap((post) =>
|
||||
post.authorsMeta.map((authorMeta) => unicornProfilePicObj[authorMeta.id])
|
||||
);
|
||||
res.send({ posts, totalPosts: posts.length, unicornProfilePicMap });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user