fix: soo many lint errors
This commit is contained in:
@@ -7,7 +7,7 @@ export default function Error404() {
|
||||
<Head>
|
||||
<title>404 - Page not found</title>
|
||||
</Head>
|
||||
<MainLayout>
|
||||
<MainLayout url="">
|
||||
<div class="px-8 text-white mt-10">
|
||||
<div class="max-w-screen-md mx-auto flex flex-col items-center justify-center">
|
||||
<h1 class="text-4xl font-bold">404 - Page not found</h1>
|
||||
|
||||
@@ -16,7 +16,6 @@ export const handler: Handlers = {
|
||||
if (!("session" in ctx.state)) {
|
||||
throw new AccessDeniedError();
|
||||
}
|
||||
console.log({ logs });
|
||||
return ctx.render({
|
||||
logs: logs.map((l) => {
|
||||
return {
|
||||
@@ -30,7 +29,7 @@ export const handler: Handlers = {
|
||||
|
||||
function LogLine(
|
||||
{ log }: {
|
||||
log: Log;
|
||||
log: Log & { html?: string };
|
||||
},
|
||||
) {
|
||||
return (
|
||||
@@ -53,7 +52,8 @@ function LogLine(
|
||||
</div>
|
||||
<div
|
||||
class="text-white"
|
||||
dangerouslySetInnerHTML={{ __html: log.html }}
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{ __html: log.html ?? "" }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -46,7 +46,7 @@ async function processCreateArticle(
|
||||
const title = result?.title || aiMeta?.headline || "";
|
||||
const id = toUrlSafeString(title);
|
||||
|
||||
const newArticle: Article = {
|
||||
const newArticle: ArticleResource["content"] = {
|
||||
_type: "Article",
|
||||
headline: title,
|
||||
articleBody: result.content,
|
||||
|
||||
@@ -60,7 +60,7 @@ function parseParams(reqUrl: URL): ImageParams | string {
|
||||
}
|
||||
}
|
||||
// Helper function to generate ETag
|
||||
async function generateETag(content: ArrayBuffer): Promise<string> {
|
||||
async function generateETag(content: Uint8Array<ArrayBuffer>): Promise<string> {
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
|
||||
return `"${
|
||||
Array.from(new Uint8Array(hashBuffer))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
||||
import * as tmdb from "@lib/tmdb.ts";
|
||||
import { isString, safeFileName } from "@lib/string.ts";
|
||||
import { formatDate, isString, safeFileName } from "@lib/string.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import {
|
||||
AccessDeniedError,
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "@lib/errors.ts";
|
||||
import { createRecommendationResource } from "@lib/recommendation.ts";
|
||||
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
|
||||
const POST = async (
|
||||
req: Request,
|
||||
@@ -20,7 +21,9 @@ const POST = async (
|
||||
throw new AccessDeniedError();
|
||||
}
|
||||
|
||||
const movie = await fetchResource(`movies/${ctx.params.name}`);
|
||||
const movie = await fetchResource<ReviewResource>(
|
||||
`movies/${ctx.params.name}`,
|
||||
);
|
||||
if (!movie) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
@@ -33,27 +36,28 @@ const POST = async (
|
||||
}
|
||||
|
||||
const movieDetails = await tmdb.getMovie(tmdbId);
|
||||
const movieCredits = !movie.meta?.author &&
|
||||
const movieCredits = !movie.content?.author &&
|
||||
await tmdb.getMovieCredits(tmdbId);
|
||||
|
||||
const releaseDate = movieDetails.release_date;
|
||||
if (releaseDate && !movie.meta?.date) {
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.date = new Date(releaseDate);
|
||||
if (releaseDate && !movie.content?.datePublished) {
|
||||
movie.content = movie.content || {};
|
||||
movie.content.datePublished = formatDate(new Date(releaseDate));
|
||||
}
|
||||
|
||||
const director = movieCredits?.crew?.filter?.((person) =>
|
||||
person.job === "Director"
|
||||
)[0];
|
||||
if (director && !movie.meta?.author) {
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.author = director.name;
|
||||
const director = movieCredits &&
|
||||
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
|
||||
if (director && !movie.content?.author) {
|
||||
movie.content = movie.content || {};
|
||||
movie.content.author = {
|
||||
_type: "Person",
|
||||
name: director.name,
|
||||
};
|
||||
}
|
||||
|
||||
if (movieDetails.genres) {
|
||||
movie.tags = [
|
||||
movie.content.keywords = [
|
||||
...new Set([
|
||||
...(movie.tags?.map((g) => g.toLowerCase()) || []),
|
||||
...(movie.content.keywords?.map((g) => g.toLowerCase()) || []),
|
||||
...movieDetails.genres.map((g) =>
|
||||
g.name?.toLowerCase().replaceAll(" ", "-")
|
||||
),
|
||||
@@ -61,22 +65,22 @@ const POST = async (
|
||||
];
|
||||
}
|
||||
|
||||
if (!movie.id) {
|
||||
movie.id = tmdbId;
|
||||
if (!movie.name) {
|
||||
movie.name = tmdbId;
|
||||
}
|
||||
|
||||
let finalPath = "";
|
||||
const posterPath = movieDetails.poster_path;
|
||||
if (posterPath && !movie.meta?.image) {
|
||||
if (posterPath && !movie.content?.image) {
|
||||
const poster = await tmdb.getMoviePoster(posterPath);
|
||||
const extension = fileExtension(posterPath);
|
||||
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
|
||||
await createResource(finalPath, poster);
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.image = finalPath;
|
||||
movie.content = movie.content || {};
|
||||
movie.content.image = finalPath;
|
||||
}
|
||||
|
||||
await createResource(`movies/${safeFileName(movie.id)}.md`, movie);
|
||||
await createResource(`movies/${safeFileName(movie.name)}.md`, movie);
|
||||
|
||||
createRecommendationResource(movie, movieDetails.overview);
|
||||
|
||||
|
||||
@@ -48,7 +48,14 @@ async function processCreateRecipeFromUrl(
|
||||
}
|
||||
|
||||
if (!recipe) {
|
||||
recipe = await openai.extractRecipe(result.content);
|
||||
const res = await openai.extractRecipe(result.content);
|
||||
if (!res || "errorMessages" in res) {
|
||||
const errorMessage = res?.errorMessages?.[0] ||
|
||||
"could not extract recipe";
|
||||
streamResponse.enqueue(`failed to extract recipe: ${errorMessage}`);
|
||||
return;
|
||||
}
|
||||
recipe = res;
|
||||
}
|
||||
|
||||
const id = safeFileName(recipe?.name || "");
|
||||
|
||||
@@ -25,11 +25,14 @@ export function parseJsonLdToRecipeSchema(jsonLdContent: string) {
|
||||
);
|
||||
|
||||
const instructions = Array.isArray(data.recipeInstructions)
|
||||
? data.recipeInstructions.map((instr) => {
|
||||
? data.recipeInstructions.map((instr: unknown) => {
|
||||
if (!instr) return "";
|
||||
if (typeof instr === "string") return instr;
|
||||
if (typeof instr === "object" && instr.text) return instr.text;
|
||||
if (typeof instr === "object" && "text" in instr && instr.text) {
|
||||
return instr.text;
|
||||
}
|
||||
return "";
|
||||
}).filter((instr) => instr.trim() !== "")
|
||||
}).filter((instr: string) => instr.trim() !== "")
|
||||
: [];
|
||||
|
||||
// Parse servings
|
||||
@@ -53,7 +56,7 @@ export function parseJsonLdToRecipeSchema(jsonLdContent: string) {
|
||||
title: data.name || "Unnamed Recipe",
|
||||
image: pickImage(image || data.image || ""),
|
||||
author: Array.isArray(data.author)
|
||||
? data.author.map((a: any) => a.name).join(", ")
|
||||
? data.author.map((a: { name: string }) => a.name).join(", ")
|
||||
: data.author?.name || "",
|
||||
description: data.description || "",
|
||||
ingredients,
|
||||
@@ -81,7 +84,7 @@ function pickImage(images: string | string[]): string {
|
||||
return images;
|
||||
}
|
||||
|
||||
function parseServings(servingsData: any): number {
|
||||
function parseServings(servingsData: unknown): number {
|
||||
if (typeof servingsData === "string") {
|
||||
const match = servingsData.match(/\d+/);
|
||||
return match ? parseInt(match[0], 10) : 1;
|
||||
|
||||
@@ -11,7 +11,6 @@ export const handler: Handlers = {
|
||||
}
|
||||
|
||||
const recommendations = await getSimilarMovies(ctx.params.id);
|
||||
console.log({ recommendations });
|
||||
|
||||
return json(recommendations);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
||||
import * as tmdb from "@lib/tmdb.ts";
|
||||
import { safeFileName } from "@lib/string.ts";
|
||||
@@ -37,42 +36,43 @@ const POST = async (
|
||||
}
|
||||
|
||||
const seriesDetails = await tmdb.getSeries(tmdbId);
|
||||
const seriesCredits = !series.meta?.author &&
|
||||
const seriesCredits = !series?.content?.author &&
|
||||
await tmdb.getSeriesCredits(tmdbId);
|
||||
|
||||
const releaseDate = seriesDetails.first_air_date;
|
||||
if (releaseDate && series.meta?.date) {
|
||||
series.meta.date = new Date(releaseDate);
|
||||
if (releaseDate && series.content?.datePublished) {
|
||||
series.content.datePublished = new Date(releaseDate).toISOString();
|
||||
}
|
||||
const posterPath = seriesDetails.poster_path;
|
||||
const director = seriesCredits &&
|
||||
seriesCredits.crew?.filter?.((person) => person.job === "Director")[0] ||
|
||||
seriesDetails?.created_by?.[0];
|
||||
if (director && director.name && !series.meta?.author) {
|
||||
series.author = series.author || {};
|
||||
series.author["_type"] = "Person";
|
||||
series.author.name = director.name;
|
||||
if (director && director.name && !series.content?.author) {
|
||||
series.content.author = series.content.author || {
|
||||
_type: "Person",
|
||||
name: director.name,
|
||||
};
|
||||
}
|
||||
|
||||
if (seriesDetails.genres) {
|
||||
series.keywords = [
|
||||
series.content.keywords = [
|
||||
...new Set([
|
||||
...(series.tags?.map((t) => t.toLowerCase()) || []),
|
||||
...(series.content.keywords?.map((t) => t.toLowerCase()) || []),
|
||||
...seriesDetails.genres.map((g) => g.name?.toLowerCase()),
|
||||
].filter(isString)),
|
||||
];
|
||||
}
|
||||
|
||||
let finalPath = "";
|
||||
if (posterPath && !series.meta?.image) {
|
||||
if (posterPath && !series.content?.image) {
|
||||
const poster = await tmdb.getMoviePoster(posterPath);
|
||||
const extension = fileExtension(posterPath);
|
||||
|
||||
finalPath = `series/images/${safeFileName(name)}_cover.${extension}`;
|
||||
await createResource(finalPath, poster);
|
||||
series.image = finalPath;
|
||||
series.content.image = finalPath;
|
||||
}
|
||||
await createResource(`series/${safeFileName(series.id)}.md`, series);
|
||||
await createResource(`series/${safeFileName(series.name)}.md`, series);
|
||||
|
||||
return json(series);
|
||||
};
|
||||
|
||||
@@ -11,11 +11,14 @@ import { Star } from "@components/Stars.tsx";
|
||||
import { MetaTags } from "@components/MetaTags.tsx";
|
||||
import { fetchResource } from "@lib/marka/index.ts";
|
||||
import { ArticleResource } from "@lib/marka/schema.ts";
|
||||
import { parseRating } from "@lib/helpers.ts";
|
||||
|
||||
export const handler: Handlers<{ article: ArticleResource; session: unknown }> =
|
||||
{
|
||||
async GET(_, ctx) {
|
||||
const article = await fetchResource(`articles/${ctx.params.name}.md`);
|
||||
const article = await fetchResource<ArticleResource>(
|
||||
`articles/${ctx.params.name}.md`,
|
||||
);
|
||||
if (!article) {
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
@@ -24,16 +27,22 @@ export const handler: Handlers<{ article: ArticleResource; session: unknown }> =
|
||||
};
|
||||
|
||||
export default function Greet(
|
||||
props: PageProps<{ article: Article; session: Record<string, string> }>,
|
||||
props: PageProps<
|
||||
{ article: ArticleResource; session: Record<string, string> }
|
||||
>,
|
||||
) {
|
||||
const { article, session } = props.data;
|
||||
|
||||
const { author = "", date = "", articleBody = "" } = article?.content || {};
|
||||
const { author, datePublished, reviewRating, articleBody = "" } =
|
||||
article?.content || {};
|
||||
|
||||
const content = renderMarkdown(
|
||||
removeImage(articleBody, article.image?.url),
|
||||
);
|
||||
|
||||
const rating = reviewRating?.ratingValue &&
|
||||
parseRating(reviewRating.ratingValue);
|
||||
|
||||
return (
|
||||
<MainLayout
|
||||
url={props.url}
|
||||
@@ -62,36 +71,35 @@ export default function Greet(
|
||||
</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={[
|
||||
author && {
|
||||
title: author,
|
||||
href: `/?q=${encodeURIComponent(author)}`,
|
||||
author?.name && {
|
||||
title: author.name,
|
||||
href: `/?q=${encodeURIComponent(author?.name)}`,
|
||||
},
|
||||
date.toString(),
|
||||
datePublished?.toString(),
|
||||
]}
|
||||
>
|
||||
{article.content.rating && <Star rating={article.content.rating} />}
|
||||
{rating && <Star rating={rating} />}
|
||||
</PageHero.Subline>
|
||||
</PageHero.Footer>
|
||||
</PageHero>
|
||||
{article.content?.tags?.length > 0 && (
|
||||
{article.content?.keywords?.length && (
|
||||
<>
|
||||
<br />
|
||||
<HashTags tags={article.content.tags} />
|
||||
<HashTags tags={article.content.keywords} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<div class="px-8 text-white mt-10">
|
||||
{isYoutubeLink(article.content.url) && (
|
||||
{(article.content.url && isYoutubeLink(article.content.url)) && (
|
||||
<YoutubePlayer link={article.content.url} />
|
||||
)}
|
||||
<pre
|
||||
class="whitespace-break-spaces markdown-body"
|
||||
data-color-mode="dark"
|
||||
data-dark-theme="dark"
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{ __html: content || "" }}
|
||||
>
|
||||
{content || ""}
|
||||
</pre>
|
||||
/>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { type ArticleResource } from "@lib/marka/schema.ts";
|
||||
import { type ArticleResource, GenericResource } from "@lib/marka/schema.ts";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { Grid } from "@components/Grid.tsx";
|
||||
import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
import { Link } from "@islands/Link.tsx";
|
||||
import { listResources } from "@lib/marka/index.ts";
|
||||
@@ -15,7 +14,7 @@ export const handler: Handlers<
|
||||
{ articles: ArticleResource[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const articles = await listResources("articles");
|
||||
const articles = await listResources<ArticleResource>("articles");
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, types: ["article"] });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PageProps, RouteContext } from "$fresh/server.ts";
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { ReviewResource, ReviewSchema } from "@lib/marka/schema.ts";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
import { removeImage, renderMarkdown } from "@lib/markdown.ts";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
@@ -24,12 +24,16 @@ export default async function Greet(
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
|
||||
const { author = "", datePublished = "", reviewBody } = movie.content;
|
||||
const { author, datePublished, reviewBody = "", reviewRating } =
|
||||
movie.content;
|
||||
|
||||
const content = renderMarkdown(
|
||||
removeImage(reviewBody || "", movie.content.image),
|
||||
removeImage(reviewBody, movie.content.image),
|
||||
);
|
||||
|
||||
const rating = reviewRating?.ratingValue &&
|
||||
parseRating(reviewRating.ratingValue);
|
||||
|
||||
return (
|
||||
<MainLayout url={props.url} title={`Movie > ${movie.name}`} context={movie}>
|
||||
<RedirectSearchHandler />
|
||||
@@ -53,37 +57,33 @@ export default async function Greet(
|
||||
</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={[
|
||||
author && {
|
||||
title: author?.name,
|
||||
author?.name &&
|
||||
{
|
||||
title: author.name,
|
||||
href: `/?q=${encodeURIComponent(author?.name)}`,
|
||||
},
|
||||
datePublished.toString(),
|
||||
datePublished?.toString(),
|
||||
]}
|
||||
>
|
||||
{movie.content.reviewRating && (
|
||||
<Star
|
||||
rating={parseRating(movie.content?.reviewRating?.ratingValue)}
|
||||
/>
|
||||
)}
|
||||
{rating && <Star rating={rating} />}
|
||||
</PageHero.Subline>
|
||||
</PageHero.Footer>
|
||||
</PageHero>
|
||||
{false && (
|
||||
{movie.name && (
|
||||
<Recommendations
|
||||
id={movie.id}
|
||||
id={movie.name}
|
||||
type="movie"
|
||||
/>
|
||||
)}
|
||||
<div class="px-8 text-white mt-10">
|
||||
{movie?.content?.reviewBody?.length > 80
|
||||
? <h2 class="text-4xl font-bold mb-4">Review</h2>
|
||||
: <></>}
|
||||
{reviewBody?.length > 80 && (
|
||||
<h2 class="text-4xl font-bold mb-4">Review</h2>
|
||||
)}
|
||||
<pre
|
||||
class="whitespace-break-spaces"
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{ __html: content || "" }}
|
||||
>
|
||||
{content}
|
||||
</pre>
|
||||
/>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
import { GenericResource, ReviewResource } from "@lib/marka/schema.ts";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
import { Grid } from "@components/Grid.tsx";
|
||||
import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { PageProps } from "$fresh/server.ts";
|
||||
import { listResources } from "@lib/marka/index.ts";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { parseRating } from "@lib/helpers.ts";
|
||||
|
||||
function sortOptional(a: number | string = 0, b: number | string = 0) {
|
||||
return (parseRating(a) > parseRating(b)) ? 1 : -1;
|
||||
}
|
||||
|
||||
export default async function MovieIndex(
|
||||
props: PageProps<
|
||||
{ movies: ReviewResource[] | null; searchResults: GenericResource[] }
|
||||
>,
|
||||
) {
|
||||
const allMovies = await listResources("movies");
|
||||
const allMovies = await listResources<ReviewResource>("movies");
|
||||
const searchParams = parseResourceUrl(props.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, types: ["movie"] });
|
||||
const movies = allMovies.sort((a, b) =>
|
||||
a?.content?.reviewRating?.ratingValue >
|
||||
b?.content?.reviewRating?.ratingValue
|
||||
? -1
|
||||
: 1
|
||||
sortOptional(
|
||||
a.content.reviewRating?.ratingValue,
|
||||
b.content.reviewRating?.ratingValue,
|
||||
)
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -13,13 +13,16 @@ import { MetaTags } from "@components/MetaTags.tsx";
|
||||
import { fetchResource } from "@lib/marka/index.ts";
|
||||
import { RecipeResource } from "@lib/marka/schema.ts";
|
||||
import { parseIngredients } from "@lib/parseIngredient.ts";
|
||||
import { parseRating } from "@lib/helpers.ts";
|
||||
|
||||
export const handler: Handlers<
|
||||
{ recipe: RecipeResource; session: unknown } | null
|
||||
> = {
|
||||
async GET(_, ctx) {
|
||||
try {
|
||||
const recipe = await fetchResource(`recipes/${ctx.params.name}.md`);
|
||||
const recipe = await fetchResource<RecipeResource>(
|
||||
`recipes/${ctx.params.name}.md`,
|
||||
);
|
||||
if (!recipe) {
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
@@ -59,6 +62,7 @@ function ValidRecipe({
|
||||
.map((instruction) => {
|
||||
return (
|
||||
<li
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: renderMarkdown(instruction),
|
||||
}}
|
||||
@@ -72,17 +76,20 @@ function ValidRecipe({
|
||||
}
|
||||
|
||||
export default function Page(
|
||||
props: PageProps<{ recipe: Recipe; session: Record<string, string> }>,
|
||||
props: PageProps<{ recipe: RecipeResource; session: Record<string, string> }>,
|
||||
) {
|
||||
const { recipe, session } = props.data;
|
||||
|
||||
const portion = recipe.recipeYield;
|
||||
const portion = recipe.content.recipeYield;
|
||||
const amount = useSignal(portion || 1);
|
||||
|
||||
const subline = [
|
||||
recipe?.content?.prepTime && `Duration ${recipe?.content?.prepTime}`,
|
||||
recipe?.content?.totalTime && `Duration ${recipe?.content?.totalTime}`,
|
||||
].filter(Boolean) as string[];
|
||||
|
||||
const rating = recipe.content.reviewRating?.ratingValue &&
|
||||
parseRating(recipe.content.reviewRating.ratingValue);
|
||||
|
||||
return (
|
||||
<MainLayout
|
||||
url={props.url}
|
||||
@@ -106,13 +113,13 @@ export default function Page(
|
||||
)}
|
||||
</PageHero.Header>
|
||||
<PageHero.Footer>
|
||||
<PageHero.Title link={recipe.content?.link}>
|
||||
<PageHero.Title link={recipe.content?.url}>
|
||||
{recipe.content.name}
|
||||
</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={subline}
|
||||
>
|
||||
{recipe.meta?.rating && <Star rating={recipe.meta?.rating} />}
|
||||
{rating && <Star rating={rating} />}
|
||||
</PageHero.Subline>
|
||||
</PageHero.Footer>
|
||||
</PageHero>
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { Recipe } from "@lib/recipeSchema.ts";
|
||||
import { Grid } from "@components/Grid.tsx";
|
||||
import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
import { fetchResource, listResources } from "@lib/marka/index.ts";
|
||||
import { listResources } from "@lib/marka/index.ts";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { GenericResource, RecipeResource } from "@lib/marka/schema.ts";
|
||||
|
||||
export const handler: Handlers<
|
||||
{ recipes: Recipe[] | null; searchResults?: GenericResource[] }
|
||||
{ recipes: RecipeResource[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const recipes = await listResources("recipes");
|
||||
const recipes = await listResources<RecipeResource>("recipes");
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, types: ["recipe"] });
|
||||
@@ -24,7 +23,7 @@ export const handler: Handlers<
|
||||
|
||||
export default function Greet(
|
||||
props: PageProps<
|
||||
{ recipes: Recipe[] | null; searchResults: GenericResource[] }
|
||||
{ recipes: RecipeResource[] | null; searchResults: GenericResource[] }
|
||||
>,
|
||||
) {
|
||||
const { recipes, searchResults } = props.data;
|
||||
|
||||
@@ -13,7 +13,9 @@ import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
|
||||
export const handler: Handlers<{ serie: ReviewResource; session: unknown }> = {
|
||||
async GET(_, ctx) {
|
||||
const serie = await fetchResource(`series/${ctx.params.name}.md`);
|
||||
const serie = await fetchResource<ReviewResource>(
|
||||
`series/${ctx.params.name}.md`,
|
||||
);
|
||||
|
||||
if (!serie) {
|
||||
return ctx.renderNotFound();
|
||||
@@ -27,16 +29,19 @@ export default function Greet(
|
||||
) {
|
||||
const { serie, session } = props.data;
|
||||
|
||||
const { author = "", datePublished = "", reviewBody } = serie?.content || {};
|
||||
const { author, datePublished, reviewBody = "" } = serie?.content || {};
|
||||
|
||||
const content = renderMarkdown(
|
||||
removeImage(reviewBody, serie.image?.url),
|
||||
);
|
||||
|
||||
const rating = serie.content.reviewRating?.ratingValue &&
|
||||
parseRating(serie.content.reviewRating.ratingValue);
|
||||
|
||||
return (
|
||||
<MainLayout
|
||||
url={props.url}
|
||||
title={`Serie > ${serie.content?.name}`}
|
||||
title={`Serie > ${serie.content?.itemReviewed?.name}`}
|
||||
context={serie}
|
||||
>
|
||||
<RedirectSearchHandler />
|
||||
@@ -59,37 +64,33 @@ export default function Greet(
|
||||
<PageHero.Title>{serie.name}</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={[
|
||||
author && {
|
||||
author?.name &&
|
||||
{
|
||||
title: author.name,
|
||||
href: `/?q=${encodeURIComponent(author)}`,
|
||||
href: `/?q=${encodeURIComponent(author?.name)}`,
|
||||
},
|
||||
datePublished.toString(),
|
||||
datePublished?.toString(),
|
||||
]}
|
||||
>
|
||||
{serie.content?.reviewRating && (
|
||||
<Star
|
||||
rating={parseRating(serie.content?.reviewRating?.ratingValue)}
|
||||
/>
|
||||
)}
|
||||
{rating && <Star rating={rating} />}
|
||||
</PageHero.Subline>
|
||||
</PageHero.Footer>
|
||||
</PageHero>
|
||||
{serie.content?.tags?.length > 0 && (
|
||||
{serie.content?.keywords?.length && (
|
||||
<>
|
||||
<br />
|
||||
<HashTags tags={serie.content?.tags} />
|
||||
<HashTags tags={serie.content?.keywords} />
|
||||
</>
|
||||
)}
|
||||
<div class="px-8 text-white mt-10">
|
||||
{serie?.content?.reviewBody?.length > 80
|
||||
? <h2 class="text-4xl font-bold mb-4">Review</h2>
|
||||
: <></>}
|
||||
{serie?.content?.reviewBody?.length && (
|
||||
<h2 class="text-4xl font-bold mb-4">Review</h2>
|
||||
)}
|
||||
<pre
|
||||
class="whitespace-break-spaces"
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{ __html: content || "" }}
|
||||
>
|
||||
{content}
|
||||
</pre>
|
||||
/>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
|
||||
@@ -13,7 +13,7 @@ export const handler: Handlers<
|
||||
{ series: ReviewResource[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const series = await listResources("series");
|
||||
const series = await listResources<ReviewResource>("series");
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, types: ["series"] });
|
||||
|
||||
Reference in New Issue
Block a user