This commit is contained in:
Shusui MOYATANI
2023-03-17 09:38:28 +09:00
parent 158d0e3a20
commit c34143065b
23 changed files with 421 additions and 246 deletions

View File

@@ -1,29 +1,13 @@
import { Component, createSignal, Show } from 'solid-js';
import { ContentWarning } from '@/core/event';
import { Component, createEffect, createSignal, Show } from 'solid-js';
import { fixUrl } from '@/utils/imageUrl';
type ImageDisplayProps = {
url: string;
contentWarning: ContentWarning;
};
const fixUrl = (url: URL): string => {
const result = new URL(url);
if (url.host === 'i.imgur.com') {
const match = url.pathname.match(/^\/([a-zA-Z0-9]+)\.(jpg|jpeg|png|gif)/);
if (match != null) {
const imageId = match[1];
result.pathname = `${imageId}l.webp`;
}
} else if (url.host === 'i.gyazo.com') {
result.host = 'thumb.gyazo.com';
result.pathname = `/thumb/640_w${url.pathname}`;
}
return result.toString();
initialHidden: boolean;
};
const ImageDisplay: Component<ImageDisplayProps> = (props) => {
const [hidden, setHidden] = createSignal(props.contentWarning.contentWarning);
const url = () => new URL(props.url);
const [hidden, setHidden] = createSignal(props.initialHidden);
return (
<Show
@@ -40,7 +24,7 @@ const ImageDisplay: Component<ImageDisplayProps> = (props) => {
<a class="my-2 block" href={props.url} target="_blank" rel="noopener noreferrer">
<img
class="inline-block max-h-64 max-w-full rounded object-contain shadow hover:shadow-md"
src={fixUrl(url())}
src={fixUrl(new URL(props.url)).toString()}
alt={props.url}
/>
</a>