mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-18 22:44:26 +01:00
feat: support AVIF image
This commit is contained in:
@@ -2,7 +2,7 @@ import { Component, createSignal, Show } from 'solid-js';
|
|||||||
|
|
||||||
import SafeLink from '@/components/utils/SafeLink';
|
import SafeLink from '@/components/utils/SafeLink';
|
||||||
import { useTranslation } from '@/i18n/useTranslation';
|
import { useTranslation } from '@/i18n/useTranslation';
|
||||||
import { fixUrl } from '@/utils/url';
|
import { thumbnailUrl } from '@/utils/url';
|
||||||
|
|
||||||
type ImageDisplayProps = {
|
type ImageDisplayProps = {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -30,7 +30,7 @@ const ImageDisplay: Component<ImageDisplayProps> = (props) => {
|
|||||||
<img
|
<img
|
||||||
ref={imageRef}
|
ref={imageRef}
|
||||||
class="max-h-64 max-w-full rounded object-contain shadow hover:shadow-md"
|
class="max-h-64 max-w-full rounded object-contain shadow hover:shadow-md"
|
||||||
src={fixUrl(props.url)}
|
src={thumbnailUrl(props.url)}
|
||||||
alt={props.url}
|
alt={props.url}
|
||||||
/>
|
/>
|
||||||
</SafeLink>
|
</SafeLink>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import assert from 'assert';
|
|||||||
|
|
||||||
import { describe, it } from 'vitest';
|
import { describe, it } from 'vitest';
|
||||||
|
|
||||||
import { fixUrl } from '@/utils/url';
|
import { thumbnailUrl } from '@/utils/url';
|
||||||
|
|
||||||
describe('fixUrl', () => {
|
describe('thumbnailUrl', () => {
|
||||||
it('should return an image url for a given imgur.com URL with additional path', () => {
|
it('should return an image url for a given imgur.com URL with additional path', () => {
|
||||||
const actual = fixUrl('https://imgur.com/uBf5Qts.jpeg');
|
const actual = thumbnailUrl('https://imgur.com/uBf5Qts.jpeg');
|
||||||
const expected = 'https://i.imgur.com/uBf5Qtsl.webp';
|
const expected = 'https://i.imgur.com/uBf5Qtsl.webp';
|
||||||
assert.deepStrictEqual(actual, expected);
|
assert.deepStrictEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export const isImageUrl = (urlString: string): boolean => {
|
export const isImageUrl = (urlString: string): boolean => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(urlString);
|
const url = new URL(urlString);
|
||||||
return /\.(jpeg|jpg|png|gif|webp|apng|svg)$/i.test(url.pathname);
|
return /\.(jpeg|jpg|png|gif|webp|avif|apng|svg)$/i.test(url.pathname);
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,10 @@ export const isVideoUrl = (urlString: string): boolean => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fixUrl = (urlString: string): string => {
|
/**
|
||||||
|
* Generate a URL of thumbnail for a given URL.
|
||||||
|
*/
|
||||||
|
export const thumbnailUrl = (urlString: string): string => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(urlString);
|
const url = new URL(urlString);
|
||||||
// Imgur
|
// Imgur
|
||||||
|
|||||||
Reference in New Issue
Block a user