diff --git a/components/Card.tsx b/components/Card.tsx
index d5fc7b2..13389b3 100644
--- a/components/Card.tsx
+++ b/components/Card.tsx
@@ -1,3 +1,6 @@
+import { isYoutubeLink } from "@lib/string.ts";
+import { IconBrandYoutube } from "@components/icons.tsx";
+
export function Card(
{ link, title, image }: { link?: string; title?: string; image?: string },
) {
@@ -18,7 +21,8 @@ export function Card(
{
const documents = await response.json();
cache.setDocuments(documents);
+ typesense.synchronize();
+
return documents;
}
diff --git a/lib/hooks/useEventListener.ts b/lib/hooks/useEventListener.ts
index d3393ef..ba0e1e8 100644
--- a/lib/hooks/useEventListener.ts
+++ b/lib/hooks/useEventListener.ts
@@ -5,6 +5,7 @@ export function useEventListener(
handler: (event: T) => void,
element = window,
) {
+ console.log("Add Eventlistener", { eventName, element, handler });
// Create a ref that stores handler
const savedHandler = useRef<(event: Event) => void>();
diff --git a/lib/typesense.ts b/lib/typesense.ts
index 4277949..61be77f 100644
--- a/lib/typesense.ts
+++ b/lib/typesense.ts
@@ -1,9 +1,10 @@
-import { Client } from "https://raw.githubusercontent.com/bradenmacdonald/typesense-deno/main/mod.ts";
+import { Client } from "typesense";
import { TYPESENSE_API_KEY, TYPESENSE_URL } from "@lib/env.ts";
import { getAllMovies } from "@lib/resource/movies.ts";
import { getAllRecipes } from "@lib/resource/recipes.ts";
import { getAllArticles } from "@lib/resource/articles.ts";
import { createLogger } from "@lib/log.ts";
+import { debounce } from "https://deno.land/std@0.193.0/async/mod.ts";
const log = createLogger("typesense");
@@ -73,6 +74,7 @@ async function initializeTypesense() {
{ name: "name", type: "string" },
{ name: "type", type: "string", facet: true },
{ name: "date", type: "string", optional: true },
+ { name: "author", type: "string", facet: true },
{ name: "rating", type: "int32", facet: true },
{ name: "tags", type: "string[]", facet: true },
{ name: "description", type: "string", optional: true },
@@ -111,10 +113,11 @@ async function synchronizeWithTypesense() {
description: sanitizeStringForTypesense(
resource?.description || resource?.content || "",
),
- image: resource?.meta?.image,
+ author: resource.meta?.author,
+ image: resource.meta?.image,
tags: resource?.tags || [],
- rating: resource?.meta?.rating || 0,
- date: resource?.meta?.date?.toString() || "",
+ rating: resource.meta?.rating || 0,
+ date: resource.meta?.date?.toString() || "",
type: resource.type,
};
});
@@ -133,21 +136,19 @@ async function synchronizeWithTypesense() {
limit_hits: 9999,
});
- const documentIds = allTypesenseDocuments.hits?.map((doc) =>
- doc?.document?.id
- ) as string[];
-
- // Find deleted document IDs by comparing the Typesense document IDs with the current list of resources
- const deletedDocumentIds = documentIds?.filter((id) =>
- !allResources.some((resource) => resource.id.toString() === id)
- );
+ const deletedDocumentIds = allTypesenseDocuments.hits
+ ?.map((doc) => doc?.document?.id)
+ ?.filter((id) =>
+ // Find deleted document IDs by comparing the Typesense document IDs with the current list of resources
+ !allResources.some((resource) => resource.id.toString() === id)
+ ).map((id) => client.collections("resources").documents(id).delete());
// Delete the documents with IDs found in deletedDocumentIds
- await Promise.all(
- deletedDocumentIds?.map((id) =>
- client.collections("resources").documents(id).delete()
- ),
- );
+ if (deletedDocumentIds) {
+ await Promise.all(
+ deletedDocumentIds,
+ );
+ }
log.info("data synchronized");
} catch (error) {
@@ -157,3 +158,5 @@ async function synchronizeWithTypesense() {
// Call the synchronizeWithTypesense function to trigger the synchronization
synchronizeWithTypesense();
+
+export const synchronize = debounce(synchronizeWithTypesense, 1000 * 60 * 5);
diff --git a/routes/api/movies/enhance/[name].ts b/routes/api/movies/enhance/[name].ts
index 5ac7947..7fb0341 100644
--- a/routes/api/movies/enhance/[name].ts
+++ b/routes/api/movies/enhance/[name].ts
@@ -43,8 +43,6 @@ async function updateMovieMetadata(
return root;
});
- console.log({ newDoc });
-
return createDocument(docId, newDoc);
}
diff --git a/routes/api/resources.ts b/routes/api/resources.ts
index ed0e0a9..d692b8b 100644
--- a/routes/api/resources.ts
+++ b/routes/api/resources.ts
@@ -2,10 +2,7 @@ import { Handlers } from "$fresh/server.ts";
import { BadRequestError } from "@lib/errors.ts";
import { getTypeSenseClient } from "@lib/typesense.ts";
import { json } from "@lib/helpers.ts";
-import { getArticle } from "@lib/resource/articles.ts";
-import { getMovie } from "@lib/tmdb.ts";
-import { getRecipe } from "@lib/resource/recipes.ts";
-import { getDocument } from "@lib/documents.ts";
+import { extractHashTags } from "@lib/string.ts";
export const handler: Handlers = {
async GET(req, _ctx) {
@@ -23,6 +20,11 @@ export const handler: Handlers = {
filter_by = `type:=${type}`;
}
+ const hashTags = extractHashTags(query);
+ if (hashTags?.length) {
+ //filter_by += `tags:=${}`
+ }
+
const typesenseClient = await getTypeSenseClient();
if (!typesenseClient) {
throw new Error("Query not available");