feat: admin log page
This commit is contained in:
32
routes/admin/cache/index.tsx
vendored
Normal file
32
routes/admin/cache/index.tsx
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { getCacheInfo } from "@lib/cache.ts";
|
||||
|
||||
export const handler: Handlers<
|
||||
{ cacheInfo: ReturnType<typeof getCacheInfo> }
|
||||
> = {
|
||||
GET(_, ctx) {
|
||||
return ctx.render({ 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: "recipe" }}
|
||||
>
|
||||
<code>
|
||||
<pre class="text-white">
|
||||
{JSON.stringify(cacheInfo, null, 2)}
|
||||
</pre>
|
||||
</code>
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
@ -8,7 +8,11 @@ import * as openai from "@lib/openai.ts";
|
||||
import tds from "https://cdn.skypack.dev/turndown@7.2.0";
|
||||
import { Article, createArticle } from "@lib/resource/articles.ts";
|
||||
import { getYoutubeVideoDetails } from "@lib/youtube.ts";
|
||||
import { extractYoutubeId, isYoutubeLink } from "@lib/string.ts";
|
||||
import {
|
||||
extractYoutubeId,
|
||||
isYoutubeLink,
|
||||
toUrlSafeString,
|
||||
} from "@lib/string.ts";
|
||||
import { createLogger } from "@lib/log/index.ts";
|
||||
|
||||
const parser = new DOMParser();
|
||||
@ -69,6 +73,10 @@ async function processCreateArticle(
|
||||
const url = new URL(fetchUrl);
|
||||
|
||||
function makeUrlAbsolute(src: string) {
|
||||
if (src.startsWith("//")) {
|
||||
return "https:" + src;
|
||||
}
|
||||
|
||||
if (src.startsWith("/")) {
|
||||
return `${url.origin}${src.replace(/$\//, "")}`;
|
||||
}
|
||||
@ -98,20 +106,16 @@ async function processCreateArticle(
|
||||
|
||||
if (href.startsWith("/")) {
|
||||
return `[${content}](${url.origin}${href.replace(/$\//, "")})`;
|
||||
}
|
||||
|
||||
if (href.startsWith("#")) {
|
||||
} else if (href.startsWith("//")) {
|
||||
return `[${content}](https:${href})`;
|
||||
} else if (href.startsWith("#")) {
|
||||
if (content.length < 2) return "";
|
||||
return `[${content}](${url.href}#${href})`.replace("##", "#");
|
||||
}
|
||||
|
||||
if (!href.startsWith("https://") && !href.startsWith("http://")) {
|
||||
} else {
|
||||
return `[${content}](${url.origin.replace(/\/$/, "")}/${
|
||||
href.replace(/^\//, "")
|
||||
})`;
|
||||
}
|
||||
|
||||
return `[${content}](${href})`;
|
||||
},
|
||||
});
|
||||
|
||||
@ -125,7 +129,10 @@ async function processCreateArticle(
|
||||
metaAuthor || openai.extractAuthorName(markdown),
|
||||
]);
|
||||
|
||||
const id = shortTitle || title || "";
|
||||
console.log({ tags, shortTitle, author });
|
||||
streamResponse.enqueue("postprocessing article");
|
||||
|
||||
const id = toUrlSafeString(shortTitle || title || "");
|
||||
|
||||
const meta: Article["meta"] = {
|
||||
author: (author || "").replace("@", "twitter:"),
|
||||
@ -161,7 +168,7 @@ async function processCreateArticle(
|
||||
}
|
||||
}
|
||||
|
||||
streamResponse.enqueue("finished processing");
|
||||
streamResponse.enqueue("writing to disk");
|
||||
|
||||
await createArticle(newArticle.id, newArticle);
|
||||
|
||||
|
Reference in New Issue
Block a user