fix: some issues

This commit is contained in:
max_richter 2023-08-02 18:13:31 +02:00
parent c8c745bb05
commit b95cfcc5b4
7 changed files with 78 additions and 45 deletions

View File

@ -14,9 +14,9 @@ import * as $8 from "./routes/api/index.ts";
import * as $9 from "./routes/api/movies/[name].ts";
import * as $10 from "./routes/api/movies/enhance/[name].ts";
import * as $11 from "./routes/api/movies/index.ts";
import * as $12 from "./routes/api/recipes/[name].ts";
import * as $13 from "./routes/api/recipes/index.ts";
import * as $14 from "./routes/api/test.ts";
import * as $12 from "./routes/api/query/index.ts";
import * as $13 from "./routes/api/recipes/[name].ts";
import * as $14 from "./routes/api/recipes/index.ts";
import * as $15 from "./routes/api/tmdb/[id].ts";
import * as $16 from "./routes/api/tmdb/credits/[id].ts";
import * as $17 from "./routes/api/tmdb/query.ts";
@ -47,9 +47,9 @@ const manifest = {
"./routes/api/movies/[name].ts": $9,
"./routes/api/movies/enhance/[name].ts": $10,
"./routes/api/movies/index.ts": $11,
"./routes/api/recipes/[name].ts": $12,
"./routes/api/recipes/index.ts": $13,
"./routes/api/test.ts": $14,
"./routes/api/query/index.ts": $12,
"./routes/api/recipes/[name].ts": $13,
"./routes/api/recipes/index.ts": $14,
"./routes/api/tmdb/[id].ts": $15,
"./routes/api/tmdb/credits/[id].ts": $16,
"./routes/api/tmdb/query.ts": $17,

View File

@ -7,6 +7,7 @@ import { fixRenderedMarkdown } from "@lib/helpers.ts";
export type Article = {
id: string;
type: "article";
content: string;
name: string;
tags: string[];
@ -86,6 +87,7 @@ function parseArticle(original: string, id: string): Article {
}
return {
type: "article",
id,
name,
tags,

View File

@ -7,6 +7,7 @@ export type Movie = {
id: string;
name: string;
description: string;
type: "movie";
tags: string[];
meta: {
date: Date;
@ -27,7 +28,11 @@ export function parseMovie(original: string, id: string): Movie {
for (const child of doc.children) {
if (child.type === "yaml") {
meta = parse(child.value) as Movie["meta"];
try {
meta = (parse(child.value) || {}) as Movie["meta"];
} catch (_) {
// ignore here
}
if (meta["rating"] && typeof meta["rating"] === "string") {
meta.rating = [...meta.rating?.matchAll("⭐")].length;
@ -59,6 +64,7 @@ export function parseMovie(original: string, id: string): Movie {
}
return {
type: "movie",
id,
name,
tags,

View File

@ -8,6 +8,7 @@ import {
import { parse } from "yaml";
import { parseIngredient } from "https://esm.sh/parse-ingredient";
import { createCrud } from "@lib/crud.ts";
import { extractHashTags } from "@lib/string.ts";
export type IngredientGroup = {
name: string;
@ -23,17 +24,20 @@ export type Ingredient = {
export type Ingredients = (Ingredient | IngredientGroup)[];
export type Recipe = {
type: "recipe";
id: string;
name: string;
description?: string;
ingredients: Ingredients;
preparation?: string;
tags: string[];
meta?: {
link?: string;
image?: string;
rating?: number;
portion?: number;
author?: string;
};
name: string;
description?: string;
ingredients: Ingredients;
preparation?: string;
};
function parseIngredientItem(listItem: DocumentChild): Ingredient | undefined {
@ -154,16 +158,25 @@ export function parseRecipe(original: string, id: string): Recipe {
groups.push(group);
}
const description = getTextOfRange(groups[0], original);
let description = getTextOfRange(groups[0], original);
const ingredients = parseIngredients(groups[1]);
const preparation = getTextOfRange(groups[2], original);
const tags = extractHashTags(description || "");
if (description) {
for (const tag of tags) {
description = description.replace("#" + tag, "");
}
}
return {
type: "recipe",
id,
meta,
name,
tags,
description: description ? renderMarkdown(description) : "",
ingredients,
preparation: preparation ? renderMarkdown(preparation) : "",

42
routes/api/query/index.ts Normal file
View File

@ -0,0 +1,42 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { getAllMovies, Movie } from "@lib/resource/movies.ts";
import { Article, getAllArticles } from "@lib/resource/articles.ts";
import { getAllRecipes, Recipe } from "@lib/resource/recipes.ts";
const isResource = (
item: Movie | Article | Recipe | boolean,
): item is Movie | Article | Recipe => {
return !!item;
};
export const handler: Handlers = {
async GET(req) {
const url = new URL(req.url);
const types = url.searchParams.get("type")?.split(", ");
let resources = (await Promise.all([
(!types || types.includes("movie")) && getAllMovies(),
(!types || types.includes("article")) && getAllArticles(),
(!types || types.includes("recipe")) && getAllRecipes(),
])).flat().filter(isResource);
const tags = url.searchParams?.get("tags")?.split(",");
if (tags?.length) {
resources = resources.filter((r) => {
return tags?.every((t) => r.tags.includes(t));
});
}
const authors = url.searchParams?.get("author")?.split(",");
if (authors?.length) {
console.log({ authors });
resources = resources.filter((r) => {
return r?.meta?.author && authors.includes(r?.meta?.author);
});
}
return json(resources);
},
};

View File

@ -1,30 +0,0 @@
import { Handlers } from "$fresh/server.ts";
function GET() {
let timer: number | undefined = undefined;
const body = new ReadableStream({
start(controller) {
timer = setInterval(() => {
const message = `It is ${new Date().toISOString()}\n`;
controller.enqueue(new TextEncoder().encode(message));
}, 1000);
},
cancel() {
if (timer !== undefined) {
clearInterval(timer);
}
},
});
return new Response(body, {
headers: {
"content-type": "text/plain",
"x-content-type-options": "nosniff",
},
});
}
export const handler: Handlers = {
GET,
};

View File

@ -15,9 +15,9 @@ a {
}
@media(min-width: 640px){
.custom-grid {
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) ;
}
.custom-grid {
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) ;
}
}
.noisy-gradient::after {