dnscms, web: try supporting svgs
This commit is contained in:
@@ -174,6 +174,7 @@ WAGTAIL_SITE_NAME = "dnscms"
|
|||||||
WAGTAIL_ALLOW_UNICODE_SLUGS = False
|
WAGTAIL_ALLOW_UNICODE_SLUGS = False
|
||||||
|
|
||||||
WAGTAILIMAGES_IMAGE_MODEL = "images.CustomImage"
|
WAGTAILIMAGES_IMAGE_MODEL = "images.CustomImage"
|
||||||
|
WAGTAILIMAGES_EXTENSIONS = ["avif", "gif", "jpg", "jpeg", "png", "webp", "svg"]
|
||||||
|
|
||||||
# Search
|
# Search
|
||||||
# https://docs.wagtail.org/en/stable/topics/search/backends.html
|
# https://docs.wagtail.org/en/stable/topics/search/backends.html
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import NextImage, { ImageProps as NextImageProps } from "next/image";
|
import NextImage, { type ImageProps as NextImageProps } from "next/image";
|
||||||
import styles from "./image.module.scss";
|
import styles from "./image.module.scss";
|
||||||
|
|
||||||
type ImageProps = NextImageProps & {
|
type ImageProps = NextImageProps & {
|
||||||
@@ -7,14 +7,35 @@ type ImageProps = NextImageProps & {
|
|||||||
imageFormat?: string | null; // "original" | "bleed" | "fullWidth"
|
imageFormat?: string | null; // "original" | "bleed" | "fullWidth"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isSvgSrc(src: NextImageProps["src"]): src is string {
|
||||||
|
return typeof src === "string" && /\.svg(\?|#|$)/i.test(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MaybeNextImage(props: NextImageProps) {
|
||||||
|
if (isSvgSrc(props.src)) {
|
||||||
|
const { src, alt, width, height, className, style } = props;
|
||||||
|
return (
|
||||||
|
<img // eslint-disable-line @next/next/no-img-element
|
||||||
|
src={src}
|
||||||
|
alt={alt}
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
className={className}
|
||||||
|
style={style}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <NextImage {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
export function ImageFigure(props: ImageProps) {
|
export function ImageFigure(props: ImageProps) {
|
||||||
const { attribution, caption, imageFormat, ...nextImageProps } = props;
|
const { attribution, caption, imageFormat, ...imageProps } = props;
|
||||||
return (
|
return (
|
||||||
<figure
|
<figure
|
||||||
className={`${styles.image} ${imageFormat ? styles[imageFormat] : ""}`}
|
className={`${styles.image} ${imageFormat ? styles[imageFormat] : ""}`}
|
||||||
>
|
>
|
||||||
<div className={styles.imageWrapper}>
|
<div className={styles.imageWrapper}>
|
||||||
<NextImage {...nextImageProps} />
|
<MaybeNextImage {...imageProps} />
|
||||||
{attribution && <div className={styles.attribution}>{attribution}</div>}
|
{attribution && <div className={styles.attribution}>{attribution}</div>}
|
||||||
</div>
|
</div>
|
||||||
{caption && <figcaption>{caption}</figcaption>}
|
{caption && <figcaption>{caption}</figcaption>}
|
||||||
@@ -23,5 +44,5 @@ export function ImageFigure(props: ImageProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Image(props: NextImageProps) {
|
export function Image(props: NextImageProps) {
|
||||||
return <NextImage {...props} />;
|
return <MaybeNextImage {...props} />;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user