Render thumb #id as an inline post thumbnail in DText
- New PostThumb component fetches the post through the e621 client (cached 30 minutes, no retries) and renders its preview image linked to the in-app post page, with the post id underneath - Falls back to an external e621 link while loading or when the post cannot be fetched
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import { Spoiler } from "@/components/Spoiler";
|
||||
import { PostThumb } from "@/features/online/PostThumb";
|
||||
|
||||
export const DEFAULT_E621_BASE_URL = "https://e621.net";
|
||||
|
||||
@@ -51,7 +52,6 @@ const ENTITY_PATHS: Record<string, string> = {
|
||||
takedown: "/takedowns/{id}",
|
||||
record: "/user_feedbacks/{id}",
|
||||
ticket: "/tickets/{id}",
|
||||
thumb: "/posts/{id}",
|
||||
};
|
||||
|
||||
const LINK_RE = new RegExp(
|
||||
@@ -159,11 +159,13 @@ function linkify(text: string, keyPrefix: string, baseUrl: string): ReactNode[]
|
||||
} else if (match[11] !== undefined) {
|
||||
nodes.push(<span key={key} id={match[11]} />);
|
||||
} else if (match[12] !== undefined && match[13] !== undefined) {
|
||||
const path = ENTITY_PATHS[match[12]]?.replace("{id}", match[13]);
|
||||
const label = `${match[12]} #${match[13]}`;
|
||||
nodes.push(
|
||||
path ? anchor(key, `${baseUrl}${path}`, label) : label,
|
||||
);
|
||||
if (match[12] === "thumb") {
|
||||
nodes.push(<PostThumb key={key} postId={Number(match[13])} />);
|
||||
} else {
|
||||
const path = ENTITY_PATHS[match[12]]?.replace("{id}", match[13]);
|
||||
const label = `${match[12]} #${match[13]}`;
|
||||
nodes.push(path ? anchor(key, `${baseUrl}${path}`, label) : label);
|
||||
}
|
||||
}
|
||||
lastIndex = regex.lastIndex;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user