fix: some issues
This commit is contained in:
parent
c8c745bb05
commit
b95cfcc5b4
12
fresh.gen.ts
12
fresh.gen.ts
@ -14,9 +14,9 @@ import * as $8 from "./routes/api/index.ts";
|
|||||||
import * as $9 from "./routes/api/movies/[name].ts";
|
import * as $9 from "./routes/api/movies/[name].ts";
|
||||||
import * as $10 from "./routes/api/movies/enhance/[name].ts";
|
import * as $10 from "./routes/api/movies/enhance/[name].ts";
|
||||||
import * as $11 from "./routes/api/movies/index.ts";
|
import * as $11 from "./routes/api/movies/index.ts";
|
||||||
import * as $12 from "./routes/api/recipes/[name].ts";
|
import * as $12 from "./routes/api/query/index.ts";
|
||||||
import * as $13 from "./routes/api/recipes/index.ts";
|
import * as $13 from "./routes/api/recipes/[name].ts";
|
||||||
import * as $14 from "./routes/api/test.ts";
|
import * as $14 from "./routes/api/recipes/index.ts";
|
||||||
import * as $15 from "./routes/api/tmdb/[id].ts";
|
import * as $15 from "./routes/api/tmdb/[id].ts";
|
||||||
import * as $16 from "./routes/api/tmdb/credits/[id].ts";
|
import * as $16 from "./routes/api/tmdb/credits/[id].ts";
|
||||||
import * as $17 from "./routes/api/tmdb/query.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/[name].ts": $9,
|
||||||
"./routes/api/movies/enhance/[name].ts": $10,
|
"./routes/api/movies/enhance/[name].ts": $10,
|
||||||
"./routes/api/movies/index.ts": $11,
|
"./routes/api/movies/index.ts": $11,
|
||||||
"./routes/api/recipes/[name].ts": $12,
|
"./routes/api/query/index.ts": $12,
|
||||||
"./routes/api/recipes/index.ts": $13,
|
"./routes/api/recipes/[name].ts": $13,
|
||||||
"./routes/api/test.ts": $14,
|
"./routes/api/recipes/index.ts": $14,
|
||||||
"./routes/api/tmdb/[id].ts": $15,
|
"./routes/api/tmdb/[id].ts": $15,
|
||||||
"./routes/api/tmdb/credits/[id].ts": $16,
|
"./routes/api/tmdb/credits/[id].ts": $16,
|
||||||
"./routes/api/tmdb/query.ts": $17,
|
"./routes/api/tmdb/query.ts": $17,
|
||||||
|
@ -7,6 +7,7 @@ import { fixRenderedMarkdown } from "@lib/helpers.ts";
|
|||||||
|
|
||||||
export type Article = {
|
export type Article = {
|
||||||
id: string;
|
id: string;
|
||||||
|
type: "article";
|
||||||
content: string;
|
content: string;
|
||||||
name: string;
|
name: string;
|
||||||
tags: string[];
|
tags: string[];
|
||||||
@ -86,6 +87,7 @@ function parseArticle(original: string, id: string): Article {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
type: "article",
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
tags,
|
tags,
|
||||||
|
@ -7,6 +7,7 @@ export type Movie = {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
type: "movie";
|
||||||
tags: string[];
|
tags: string[];
|
||||||
meta: {
|
meta: {
|
||||||
date: Date;
|
date: Date;
|
||||||
@ -27,7 +28,11 @@ export function parseMovie(original: string, id: string): Movie {
|
|||||||
|
|
||||||
for (const child of doc.children) {
|
for (const child of doc.children) {
|
||||||
if (child.type === "yaml") {
|
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") {
|
if (meta["rating"] && typeof meta["rating"] === "string") {
|
||||||
meta.rating = [...meta.rating?.matchAll("⭐")].length;
|
meta.rating = [...meta.rating?.matchAll("⭐")].length;
|
||||||
@ -59,6 +64,7 @@ export function parseMovie(original: string, id: string): Movie {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
type: "movie",
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
tags,
|
tags,
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
import { parse } from "yaml";
|
import { parse } from "yaml";
|
||||||
import { parseIngredient } from "https://esm.sh/parse-ingredient";
|
import { parseIngredient } from "https://esm.sh/parse-ingredient";
|
||||||
import { createCrud } from "@lib/crud.ts";
|
import { createCrud } from "@lib/crud.ts";
|
||||||
|
import { extractHashTags } from "@lib/string.ts";
|
||||||
|
|
||||||
export type IngredientGroup = {
|
export type IngredientGroup = {
|
||||||
name: string;
|
name: string;
|
||||||
@ -23,17 +24,20 @@ export type Ingredient = {
|
|||||||
export type Ingredients = (Ingredient | IngredientGroup)[];
|
export type Ingredients = (Ingredient | IngredientGroup)[];
|
||||||
|
|
||||||
export type Recipe = {
|
export type Recipe = {
|
||||||
|
type: "recipe";
|
||||||
id: string;
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
ingredients: Ingredients;
|
||||||
|
preparation?: string;
|
||||||
|
tags: string[];
|
||||||
meta?: {
|
meta?: {
|
||||||
link?: string;
|
link?: string;
|
||||||
image?: string;
|
image?: string;
|
||||||
rating?: number;
|
rating?: number;
|
||||||
portion?: number;
|
portion?: number;
|
||||||
|
author?: string;
|
||||||
};
|
};
|
||||||
name: string;
|
|
||||||
description?: string;
|
|
||||||
ingredients: Ingredients;
|
|
||||||
preparation?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function parseIngredientItem(listItem: DocumentChild): Ingredient | undefined {
|
function parseIngredientItem(listItem: DocumentChild): Ingredient | undefined {
|
||||||
@ -154,16 +158,25 @@ export function parseRecipe(original: string, id: string): Recipe {
|
|||||||
groups.push(group);
|
groups.push(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
const description = getTextOfRange(groups[0], original);
|
let description = getTextOfRange(groups[0], original);
|
||||||
|
|
||||||
const ingredients = parseIngredients(groups[1]);
|
const ingredients = parseIngredients(groups[1]);
|
||||||
|
|
||||||
const preparation = getTextOfRange(groups[2], original);
|
const preparation = getTextOfRange(groups[2], original);
|
||||||
|
|
||||||
|
const tags = extractHashTags(description || "");
|
||||||
|
if (description) {
|
||||||
|
for (const tag of tags) {
|
||||||
|
description = description.replace("#" + tag, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
type: "recipe",
|
||||||
id,
|
id,
|
||||||
meta,
|
meta,
|
||||||
name,
|
name,
|
||||||
|
tags,
|
||||||
description: description ? renderMarkdown(description) : "",
|
description: description ? renderMarkdown(description) : "",
|
||||||
ingredients,
|
ingredients,
|
||||||
preparation: preparation ? renderMarkdown(preparation) : "",
|
preparation: preparation ? renderMarkdown(preparation) : "",
|
||||||
|
42
routes/api/query/index.ts
Normal file
42
routes/api/query/index.ts
Normal 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);
|
||||||
|
},
|
||||||
|
};
|
@ -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,
|
|
||||||
};
|
|
@ -15,9 +15,9 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media(min-width: 640px){
|
@media(min-width: 640px){
|
||||||
.custom-grid {
|
.custom-grid {
|
||||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) ;
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.noisy-gradient::after {
|
.noisy-gradient::after {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user