add unicorn data to search API response, fix type errors

This commit is contained in:
James Fenn
2023-10-19 01:59:12 -04:00
parent 84d85ceb69
commit aa3ebfbcea
12 changed files with 123 additions and 89 deletions

View File

@@ -2,7 +2,7 @@ import Fuse from "fuse.js";
import * as fs from "fs";
import * as path from "path";
import * as api from "utils/api";
import { PostInfo, CollectionInfo } from "types/index";
import { PostInfo, CollectionInfo, UnicornInfo } from "types/index";
const posts = api.getPostsByLang("en");
const collections = api.getCollectionsByLang("en");
@@ -87,5 +87,18 @@ const createCollectionIndex = () => {
const postIndex = createPostIndex();
const collectionIndex = createCollectionIndex();
const json = JSON.stringify({ postIndex, posts, collectionIndex, collections });
const unicorns: Record<string, UnicornInfo> = api
.getUnicornsByLang("en")
.reduce((obj, unicorn) => {
obj[unicorn.id] = unicorn;
return obj;
}, {});
const json = JSON.stringify({
postIndex,
posts,
collectionIndex,
collections,
unicorns,
});
fs.writeFileSync(path.resolve(process.cwd(), "./api/searchIndex.json"), json);