fix: make it work with new vite

This commit is contained in:
Max Richter
2026-01-10 19:28:09 +01:00
parent 694feb083d
commit 8d712322c0
66 changed files with 590 additions and 1544 deletions

View File

@@ -1,7 +1,6 @@
import { PageProps } from "fresh";
import { Partial } from "fresh/runtime";
import { define } from "../utils.ts";
export default function App({ Component }: PageProps) {
export default define.page(function ({ Component }) {
return (
<html>
<head>
@@ -12,9 +11,6 @@ export default function App({ Component }: PageProps) {
href="/favicon.png"
/>
<link rel="manifest" href="/site.webmanifest" />
<meta name="msapplication-TileColor" content="#da532c" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#141218" />
<link
rel="preload"
href="/fonts/work-sans-v18-latin-regular.woff2"
@@ -28,14 +24,24 @@ export default function App({ Component }: PageProps) {
type="font/woff2"
/>
<link rel="stylesheet" href="/global.css" />
<meta name="msapplication-TileColor" content="#da532c" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#141218" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style
dangerouslySetInnerHTML={{
__html: Deno.readTextFileSync("./static/global.css"),
}}
>
</style>
<title>Memorium</title>
</head>
<body f-client-nav>
<Partial name="body">
<Component />
</Partial>
<body>
<Component />
</body>
<script src="/thumbhash.js" type="module" async defer />
</html>
);
}
});

View File

@@ -20,7 +20,7 @@ export default function ErrorPage(props: PageProps) {
</Head>
<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">
<div class="max-w-3xl mx-auto flex flex-col items-center justify-center">
<h1 class="text-4xl font-bold">404 - Page not found</h1>
<p class="my-4">
The page you were looking for doesn't exist.

View File

@@ -1,10 +1,10 @@
import { resources } from "@lib/resources.ts";
import { Link } from "@islands/Link.tsx";
import { Emoji } from "@components/Emoji.tsx";
import KMenuButton from "@islands/KMenuButton.tsx";
import { PageProps } from "fresh";
import { define } from "../utils.ts";
export default function MyLayout({ Component }: PageProps) {
export default define.layout(function ({ Component }: PageProps) {
return (
<div
class="md:grid mx-auto"
@@ -14,12 +14,12 @@ export default function MyLayout({ Component }: PageProps) {
<nav class="min-h-fit rounded-3xl p-3 grid gap-3 fixed t-0">
{Object.values(resources).map((m) => {
return (
<Link
<a
href={m.link}
class="flex items-center gap-2 text-white data-[current]:bg-white data-[current]:text-black p-3 text-xl w-full rounded-2xl"
class="flex items-center gap-2 text-white data-current:bg-white data-current:text-black p-3 text-xl w-full rounded-2xl"
>
<Emoji class="w-6 h-6" name={m.emoji} /> {m.name}
</Link>
</a>
);
})}
</nav>
@@ -30,4 +30,4 @@ export default function MyLayout({ Component }: PageProps) {
<KMenuButton />
</div>
);
}
});

View File

@@ -58,4 +58,4 @@ const authMiddleware = define.middleware(async function (
}
});
export default [];
export default [authMiddleware];

View File

@@ -1,31 +0,0 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { PageProps } from "fresh";
import { getCacheInfo } from "@lib/cache.ts";
import { define } from "../../../utils.ts";
export const handler = define.handlers({
GET() {
return { data: { cacheInfo: getCacheInfo() } };
},
});
export default function Greet(
props: PageProps<
{ cacheInfo: ReturnType<typeof getCacheInfo> }
>,
) {
const { cacheInfo } = props.data;
return (
<MainLayout
url={props.url}
title="Recipes"
context={{ type: "recipes" }}
>
<code>
<pre class="text-white">
{JSON.stringify(cacheInfo, null, 2)}
</pre>
</code>
</MainLayout>
);
}

View File

@@ -1,81 +0,0 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { PageProps } from "fresh";
import { AccessDeniedError } from "@lib/errors.ts";
import { getLogs, Log } from "@lib/log/index.ts";
import { formatDate } from "@lib/string.ts";
import { renderMarkdown } from "@lib/markdown.ts";
import { define } from "../../../utils.ts";
const renderLog = (t: unknown) =>
renderMarkdown(`\`\`\`js
${typeof t === "string" ? t : JSON.stringify(t, null, 2).trim()}
\`\`\``);
export const handler = define.handlers({
async GET(ctx) {
const logs = await getLogs();
if (!("session" in ctx.state)) {
throw new AccessDeniedError();
}
return {
data: {
logs: logs.map((l) => {
return {
...l,
html: l.args.map(renderLog).join("<br/>"),
};
}),
},
};
},
});
function LogLine(
{ log }: {
log: Log & { html?: string };
},
) {
return (
<div
class="mt-4 flex flex-col gap-2 bg-gray-900 px-4 py-2 rounded-2xl max-w-3xl"
style={{ background: "var(--light)" }}
>
<div class="flex gap-2">
<span class="bg-gray-600 py-1 px-2 text-xs rounded-xl text-white">
{log.date.getHours().toString().padStart(2, "0")}:{log.date
.getMinutes().toString().padStart(2, "0")}:{log.date.getSeconds()
.toString().padStart(2, "0")} {formatDate(log.date)}
</span>
<span class="bg-gray-600 py-1 px-2 text-xs rounded-xl text-white">
{log.scope}
</span>
<span class="bg-gray-600 py-1 px-2 text-xs rounded-xl text-white">
{log.level}
</span>
</div>
<div
class="text-white"
// deno-lint-ignore react-no-danger
dangerouslySetInnerHTML={{ __html: log.html ?? "" }}
/>
</div>
);
}
export default function Greet(
{ data: { logs }, url }: PageProps<{ logs: Log[] }>,
) {
return (
<MainLayout url={url}>
<h1 class="text-white text-4xl">Logs</h1>
{logs.map((r) => {
return (
<LogLine
log={r}
/>
);
})}
</MainLayout>
);
}

View File

@@ -1,90 +0,0 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { PageProps } from "fresh";
import { getPerformances, PerformanceRes } from "@lib/performance.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { define } from "../../../utils.ts";
export const handler = define.handlers({
async GET(ctx) {
const performances = await getPerformances();
if (!("session" in ctx.state)) {
throw new AccessDeniedError();
}
return { data: { performances } };
},
});
function PerformanceLine(
{ maximum, data: [amount, min, average, max], url }: {
maximum: number;
url: string;
data: readonly [number, number, number, number];
},
) {
return (
<div
class="mt-10 flex flex-col gap-2 bg-gray-900 px-4 py-2 rounded-2xl"
style={{ background: "var(--light)" }}
>
<div style={{ color: "var(--foreground)" }}>
{url}
</div>
<div class="flex gap-2">
<span class="bg-gray-600 p-1 text-xs rounded-xl text-white">
{Math.floor(average / 1000)}ms
</span>
<span class="bg-gray-600 p-1 text-xs rounded-xl text-white">
{amount}x
</span>
</div>
<div class="" style={{ maxWidth: "75vw" }}>
<div
class="h-2 bg-red-200 rounded"
style={{
width: `${Math.floor((max / maximum) * 100)}%`,
borderRadius: "1rem 1rem 1rem 0px",
minWidth: "5px",
}}
/>
<div
class="h-2 bg-green-200 rounded"
style={{
width: `${Math.floor((average / maximum) * 100)}%`,
borderStartEndRadius: "0px",
borderRadius: "0px 0px 1rem 0px",
minWidth: "5px",
}}
/>
<div
class="h-2 bg-yellow-200 rounded"
style={{
width: `${Math.floor((min / maximum) * 100)}%`,
borderRadius: "0px 0px 1rem 1rem",
minWidth: "5px",
}}
/>
</div>
</div>
);
}
export default function Greet(
{ data: { performances }, url }: PageProps<{ performances: PerformanceRes }>,
) {
return (
<MainLayout url={url}>
<h1 class="text-white text-4xl ">Performance</h1>
{performances.res.map((r) => {
return (
<PerformanceLine
maximum={performances.max}
url={r.url}
data={r.data}
/>
);
})}
</MainLayout>
);
}

View File

@@ -16,7 +16,6 @@ export const handler = define.handlers({
throw new BadRequestError();
}
console.log(s);
const resources = await searchResource(s);
return json(resources);

View File

@@ -38,7 +38,10 @@ export const handler = define.handlers({
const releaseDate = seriesDetails.first_air_date;
if (releaseDate && series.content?.datePublished) {
series.content.datePublished = new Date(releaseDate).toISOString();
const d = new Date(releaseDate);
if (!isNaN(d.getTime())) {
series.content.datePublished = d.toISOString();
}
}
const posterPath = seriesDetails.poster_path;
const director = seriesCredits &&

View File

@@ -27,7 +27,7 @@ export const handler = define.handlers({
},
});
export default function Greet(
export default define.page(function (
props: PageProps<
{ article: ArticleResource; session: Record<string, string> }
>,
@@ -104,4 +104,4 @@ export default function Greet(
</div>
</MainLayout>
);
}
});

View File

@@ -6,7 +6,6 @@ import { Grid } from "@components/Grid.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { ResourceCard } from "@components/Card.tsx";
import { Link } from "@islands/Link.tsx";
import { listResources } from "@lib/marka/index.ts";
import { define } from "../../utils.ts";
import { TbArrowLeft } from "@preact-icons/tb";
@@ -22,7 +21,7 @@ export const handler = define.handlers({
},
});
export default define.page(function Greet(
export default define.page(function (
props: PageProps<
{ articles: ArticleResource[] | null; searchResults: GenericResource[] }
>,
@@ -36,13 +35,13 @@ export default define.page(function Greet(
searchResults={searchResults}
>
<header class="flex gap-4 items-center mb-5 md:hidden">
<Link
<a
class="px-4 ml-4 py-2 bg-gray-300 text-gray-800 rounded-lg flex items-center gap-1"
href="/"
>
<TbArrowLeft class="w-5 h-5" />
Back
</Link>
</a>
<h3 class="text-2xl text-white font-light">📝 Articles</h3>
</header>

View File

@@ -4,9 +4,10 @@ import { PageProps } from "fresh";
import { resources } from "@lib/resources.ts";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { KMenu } from "@islands/KMenu.tsx";
import { define } from "../utils.ts";
// import "@lib/telegram.ts";
export default function Home(props: PageProps) {
export default define.page(function (props: PageProps) {
return (
<>
<RedirectSearchHandler />
@@ -32,4 +33,4 @@ export default function Home(props: PageProps) {
</MainLayout>
</>
);
}
});

View File

@@ -77,7 +77,7 @@ function ValidRecipe({
);
}
export default function Page(
export default define.page(function (
props: PageProps<{ recipe: RecipeResource; session: Record<string, string> }>,
) {
const { recipe, session } = props.data;
@@ -143,4 +143,4 @@ export default function Page(
</div>
</MainLayout>
);
}
});

View File

@@ -1,4 +1,4 @@
import { Context, PageProps } from "fresh";
import { PageProps } from "fresh";
import { MainLayout } from "@components/layouts/main.tsx";
import { Grid } from "@components/Grid.tsx";
import { TbArrowLeft } from "@preact-icons/tb";
@@ -8,9 +8,10 @@ import { ResourceCard } from "@components/Card.tsx";
import { listResources } from "@lib/marka/index.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { GenericResource, RecipeResource } from "@lib/marka/schema.ts";
import { define } from "../../utils.ts";
export const handler = {
async GET(ctx: Context<{ test: number }>) {
export const handler = define.handlers({
async GET(ctx) {
const req = ctx.req;
const recipes = await listResources<RecipeResource>("recipes");
const searchParams = parseResourceUrl(req.url);
@@ -18,9 +19,9 @@ export const handler = {
await searchResource({ ...searchParams, types: ["recipes"] });
return { data: { recipes, searchResults } };
},
};
});
export default function Page(
export default define.page(function (
{ data, url }: PageProps<{
recipes: RecipeResource[] | null;
searchResults: GenericResource[];
@@ -54,4 +55,4 @@ export default function Page(
</Grid>
</MainLayout>
);
}
});

View File

@@ -26,7 +26,7 @@ export const handler = define.handlers({
},
});
export default function Greet(
export default define.page(function (
props: PageProps<{ serie: ReviewResource; session: Record<string, string> }>,
) {
const { serie, session } = props.data;
@@ -96,4 +96,4 @@ export default function Greet(
</div>
</MainLayout>
);
}
});

View File

@@ -10,9 +10,6 @@ import { GenericResource, ReviewResource } from "@lib/marka/schema.ts";
import { define } from "../../utils.ts";
import { TbArrowLeft } from "@preact-icons/tb";
// : <
// { series: ReviewResource[] | null; searchResults?: GenericResource[] }
// >
export const handler = define.handlers({
async GET(ctx) {
const req = ctx.req;
@@ -24,7 +21,7 @@ export const handler = define.handlers({
},
});
export default function Greet(
export default define.page(function (
props: PageProps<
{ series: ReviewResource[] | null; searchResults: GenericResource[] }
>,
@@ -60,4 +57,4 @@ export default function Greet(
</Grid>
</MainLayout>
);
}
});