feat: fallback to unsplash cover when article contains no image
This commit is contained in:
41
islands/KMenu/commands/enhance_article_infos.ts
Normal file
41
islands/KMenu/commands/enhance_article_infos.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { getCookie } from "@lib/string.ts";
|
||||
import { MenuEntry } from "../types.ts";
|
||||
import { ArticleResource } from "@lib/marka/schema.ts";
|
||||
import { fetchStream } from "@lib/helpers.ts";
|
||||
|
||||
export const enhanceArticleInfo: MenuEntry = {
|
||||
title: "Enhance Article Info",
|
||||
meta: "Update metadata and content from source url",
|
||||
icon: "IconReportSearch",
|
||||
cb: (state, context) => {
|
||||
state.activeState.value = "loading";
|
||||
const article = context as ArticleResource;
|
||||
|
||||
fetchStream(
|
||||
`/api/articles/enhance/${article.name}/`,
|
||||
(chunk) => {
|
||||
if (chunk.type === "error") {
|
||||
state.activeState.value = "error";
|
||||
state.loadingText.value = chunk.message;
|
||||
} else if (chunk.type == "finished") {
|
||||
state.loadingText.value = "Finished";
|
||||
setTimeout(() => {
|
||||
state.visible.value = false;
|
||||
state.activeState.value = "normal";
|
||||
globalThis.location.reload();
|
||||
}, 500);
|
||||
} else {
|
||||
state.loadingText.value = chunk.message;
|
||||
}
|
||||
},
|
||||
{ method: "POST" },
|
||||
);
|
||||
},
|
||||
visible: () => {
|
||||
const loc = globalThis["location"];
|
||||
if (!getCookie("session_cookie")) return false;
|
||||
|
||||
return (loc?.pathname?.includes("article") &&
|
||||
!loc.pathname.endsWith("articles"));
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user