Skip to content

Commit da0134d

Browse files
committed
Update: setup indexing for projects
1 parent 29d62d8 commit da0134d

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"firebase-admin": "^13.0.2",
2424
"gray-matter": "^4.0.3",
2525
"hastscript": "^7.2.0",
26+
"meilisearch": "^0.52.0",
2627
"next-mdx-remote": "^4.3.0",
2728
"rehype-autolink-headings": "^6.1.1",
2829
"rehype-external-links": "^2.0.1",

publish/index.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import rehypeKatex from "rehype-katex";
1515
import rehypeAutoLinkHeadings from "rehype-autolink-headings";
1616
import rehypeRewrite from "rehype-rewrite";
1717
import { h } from "hastscript";
18+
import { MeiliSearch } from "meilisearch";
19+
20+
const client = new MeiliSearch({
21+
host: process.env.MEILISEARCH_HOST,
22+
apiKey: process.env.MEILISEARCH_API_KEY,
23+
});
24+
1825

1926
firebaseAdmin.initializeApp({
2027
credential: firebaseAdmin.credential.cert({
@@ -68,10 +75,7 @@ async function main() {
6875
).exists;
6976

7077
const projectReactionsExists = (
71-
await firestore
72-
.collection("projectReactions")
73-
.doc(fileNameWithoutExtension)
74-
.get()
78+
await firestore.collection("projectReactions").doc(fileNameWithoutExtension).get()
7579
).exists;
7680

7781
if (!projectReactionsExists) {
@@ -81,12 +85,7 @@ async function main() {
8185
}
8286

8387
const projectContent = fs.readFileSync(
84-
path.resolve(
85-
process.cwd(),
86-
"projects",
87-
projectFolderName,
88-
projectMdxFile
89-
),
88+
path.resolve(process.cwd(), "projects", projectFolderName, projectMdxFile),
9089
"utf-8"
9190
);
9291

@@ -149,6 +148,21 @@ async function main() {
149148
},
150149
});
151150

151+
try {
152+
await client.index("projects").addDocuments([
153+
{
154+
id: fileNameWithoutExtension,
155+
title: projectMatter.data.title,
156+
description: projectMatter.data.description,
157+
content: projectMatter.content,
158+
author: projectMatter.data.author,
159+
tags: projectMatter.data.tags || [],
160+
},
161+
]);
162+
} catch (error) {
163+
console.error("Error adding document to MeiliSearch:", error);
164+
}
165+
152166
if (!projectExists) {
153167
await firestore
154168
.collection("projects")

0 commit comments

Comments
 (0)