feat: some shit

This commit is contained in:
2023-08-08 11:03:20 +02:00
parent eb1d065f1f
commit dccb6a6ecf
9 changed files with 95 additions and 19 deletions

View File

@ -3,7 +3,7 @@ import { useEffect, useRef } from "preact/hooks";
export function useEventListener<T extends Event>(
eventName: string,
handler: (event: T) => void,
element = window,
element: Window | HTMLElement = window,
) {
console.log("Add Eventlistener", { eventName, element, handler });
// Create a ref that stores handler

View File

@ -27,8 +27,8 @@ export interface GiteaOauthUser {
groups: any;
}
export type SearchResult = SearchResponse<{
id:string;
export type TypesenseDocument = {
id: string;
name: string;
type: keyof typeof resources;
date?: string;
@ -36,4 +36,6 @@ export type SearchResult = SearchResponse<{
tags: string[];
description?: string;
image?: string;
}>;
};
export type SearchResult = SearchResponse<TypesenseDocument>;

View File

@ -6,6 +6,7 @@ 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";
import { getAllSeries } from "@lib/resource/series.ts";
import { TypesenseDocument } from "@lib/types.ts";
const log = createLogger("typesense");
@ -94,6 +95,16 @@ async function initializeTypesense() {
const init = initializeTypesense();
export async function createTypesenseDocument(doc: TypesenseDocument) {
const client = await getTypeSenseClient();
if (!client) return;
await client.collections("resources").documents().create(
doc,
{ action: "upsert" },
);
}
async function synchronizeWithTypesense() {
await init;
try {