feat: some shit
This commit is contained in:
parent
aff3019768
commit
990db3ae50
@ -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(
|
||||
<div>
|
||||
{/* Recipe Card content */}
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<div class="mt-2 flex items-center gap-2">
|
||||
{isYoutubeLink(link || "") && <IconBrandYoutube />}
|
||||
{title}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -15,3 +15,4 @@ export { default as IconLogin } from "https://deno.land/x/tabler_icons_tsx@0.0.3
|
||||
export { default as IconLogout } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/logout.tsx";
|
||||
export { default as IconSearch } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/search.tsx";
|
||||
export { default as IconGhost } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/ghost.tsx";
|
||||
export { default as IconBrandYoutube } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/brand-youtube.tsx";
|
||||
|
@ -136,7 +136,6 @@ const SearchComponent = (
|
||||
debouncedFetchData(q);
|
||||
}, []);
|
||||
|
||||
console.log({ data, isLoading });
|
||||
return (
|
||||
<div class="mt-2">
|
||||
<div
|
||||
|
@ -12,6 +12,7 @@ import * as cache from "@lib/cache/documents.ts";
|
||||
import { SILVERBULLET_SERVER } from "@lib/env.ts";
|
||||
import { fixRenderedMarkdown } from "@lib/helpers.ts";
|
||||
import { createLogger } from "@lib/log.ts";
|
||||
import * as typesense from "@lib/typesense.ts";
|
||||
|
||||
export type Document = {
|
||||
name: string;
|
||||
@ -37,6 +38,8 @@ export async function getDocuments(): Promise<Document[]> {
|
||||
const documents = await response.json();
|
||||
cache.setDocuments(documents);
|
||||
|
||||
typesense.synchronize();
|
||||
|
||||
return documents;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ export function useEventListener<T extends Event>(
|
||||
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>();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -43,8 +43,6 @@ async function updateMovieMetadata(
|
||||
return root;
|
||||
});
|
||||
|
||||
console.log({ newDoc });
|
||||
|
||||
return createDocument(docId, newDoc);
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user