fix: hashtag extraction and make remote links absolute
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { Menu } from "@islands/KMenu/types.ts";
|
||||
import { Movie } from "@lib/resource/movies.ts";
|
||||
import { TMDBMovie } from "@lib/types.ts";
|
||||
import { isValidUrl } from "@lib/helpers.ts";
|
||||
import { fetchStream, isValidUrl } from "@lib/helpers.ts";
|
||||
|
||||
export const menus: Record<string, Menu> = {
|
||||
main: {
|
||||
@ -28,20 +28,24 @@ export const menus: Record<string, Menu> = {
|
||||
state.activeMenu.value = "input_link";
|
||||
state.activeState.value = "input";
|
||||
|
||||
const unsub = state.commandInput.subscribe(async (value) => {
|
||||
const unsub = state.commandInput.subscribe((value) => {
|
||||
if (isValidUrl(value)) {
|
||||
unsub();
|
||||
|
||||
state.activeState.value = "loading";
|
||||
|
||||
const response = await fetch("/api/articles/create?url=" + value);
|
||||
const newArticle = await response.json();
|
||||
|
||||
if (newArticle?.id) {
|
||||
window.location.href = "/articles/" + newArticle.id;
|
||||
}
|
||||
|
||||
state.visible.value = false;
|
||||
fetchStream("/api/articles/create?url=" + value, (chunk) => {
|
||||
console.log({ chunk: chunk.split("\n") });
|
||||
if (chunk.startsWith("id:")) {
|
||||
state.loadingText.value = "Finished";
|
||||
setTimeout(() => {
|
||||
window.location.href = "/articles/" +
|
||||
chunk.replace("id:", "").trim();
|
||||
}, 500);
|
||||
} else {
|
||||
state.loadingText.value = chunk;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -6,6 +6,7 @@ type IconKey = keyof typeof icons;
|
||||
export type MenuState = {
|
||||
activeMenu: Signal<string>;
|
||||
activeState: Signal<"input" | "error" | "normal" | "loading">;
|
||||
loadingText:Signal<string>;
|
||||
commandInput: Signal<string>;
|
||||
visible: Signal<boolean>;
|
||||
menus: Record<string, Menu>;
|
||||
|
Reference in New Issue
Block a user