feat: initial refactor to use marka as backend

This commit is contained in:
Max Richter
2025-10-28 20:15:23 +01:00
parent 0beb3b1071
commit f680b5f832
39 changed files with 245 additions and 1012 deletions

View File

@@ -1,7 +1,6 @@
import { PageProps, RouteContext } from "$fresh/server.ts";
import { MainLayout } from "@components/layouts/main.tsx";
import { getMovie, Movie } from "@lib/resource/movies.ts";
import { HashTags } from "@components/HashTags.tsx";
import { Movie } from "@lib/resource/movies.ts";
import { removeImage, renderMarkdown } from "@lib/documents.ts";
import { KMenu } from "@islands/KMenu.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
@@ -9,22 +8,24 @@ import { Recommendations } from "@islands/Recommendations.tsx";
import PageHero from "@components/PageHero.tsx";
import { Star } from "@components/Stars.tsx";
import { MetaTags } from "@components/MetaTags.tsx";
import { parseRating } from "@lib/helpers.ts";
import { fetchResource } from "@lib/resources.ts";
export default async function Greet(
props: PageProps<{ movie: Movie; session: Record<string, string> }>,
ctx: RouteContext,
) {
const movie = await getMovie(ctx.params.name);
const movie = await fetchResource(`movies/${ctx.params.name}.md`);
const session = ctx.state.session;
if (!movie) {
return ctx.renderNotFound();
}
const { author = "", date = "" } = movie.meta;
const { author = "", date = "" } = movie.content;
const content = renderMarkdown(
removeImage(movie.description || "", movie.meta.image),
removeImage(movie.content.reviewBody || "", movie.content.image),
);
return (
@@ -33,14 +34,14 @@ export default async function Greet(
<KMenu type="main" context={movie} />
<MetaTags resource={movie} />
<PageHero
image={movie.meta.image}
thumbnail={movie.meta.thumbnail}
image={movie.content.image}
thumbnail={movie.content.thumbnail}
>
<PageHero.Header>
<PageHero.BackLink href="/movies" />
{session && (
<PageHero.EditLink
href={`https://notes.max-richter.dev/Media/movies/${movie.id}`}
href={`https://notes.max-richter.dev/resources/movies/${movie.name}`}
/>
)}
</PageHero.Header>
@@ -49,13 +50,17 @@ export default async function Greet(
<PageHero.Subline
entries={[
author && {
title: author,
href: `/?q=${encodeURIComponent(author)}`,
title: author?.name,
href: `/?q=${encodeURIComponent(author?.name)}`,
},
date.toString(),
]}
>
{movie.meta.rating && <Star rating={movie.meta.rating} />}
{movie.content.reviewRating && (
<Star
rating={parseRating(movie.content.reviewRating?.ratingValue)}
/>
)}
</PageHero.Subline>
</PageHero.Footer>
</PageHero>
@@ -65,14 +70,8 @@ export default async function Greet(
type="movie"
/>
)}
{movie.tags.length > 0 && (
<>
<br />
<HashTags tags={movie.tags} />
</>
)}
<div class="px-8 text-white mt-10">
{movie?.description?.length > 80
{movie?.content?.reviewBody?.length > 80
? <h2 class="text-4xl font-bold mb-4">Review</h2>
: <></>}
<pre

View File

@@ -1,25 +1,26 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { getAllMovies, Movie } from "@lib/resource/movies.ts";
import { Movie } from "@lib/resource/movies.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 { parseResourceUrl, searchResource } from "@lib/search.ts";
import { GenericResource } from "@lib/types.ts";
import { PageProps } from "$fresh/server.ts";
import { fetchResource } from "@lib/resources.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
export default async function Greet(
props: PageProps<
{ movies: Movie[] | null; searchResults: GenericResource[] }
>,
) {
const allMovies = await getAllMovies();
const { content: allMovies } = await fetchResource("movies");
const searchParams = parseResourceUrl(props.url);
const searchResults = searchParams &&
await searchResource({ ...searchParams, types: ["movie"] });
const movies = allMovies.sort((a, b) =>
a?.meta?.rating > b?.meta?.rating ? -1 : 1
a?.content?.reviewRating?.ratingValue > b?.content?.reviewRating?.ratingValue ? -1 : 1
);
return (