Added support for multi-size images

This commit is contained in:
DrMint 2022-02-19 05:28:04 +01:00
parent 57399a60dd
commit 290fa80b31
4 changed files with 22 additions and 12 deletions

View File

@ -7,7 +7,7 @@ module.exports = {
defaultLocale: "en", defaultLocale: "en",
}, },
images: { images: {
domains: ["strapi.accords-library.com"], domains: ["img.accords-library.com"],
}, },
async redirects() { async redirects() {
return [ return [

View File

@ -2,7 +2,7 @@ import {
GetContentQuery, GetContentQuery,
GetWebsiteInterfaceQuery, GetWebsiteInterfaceQuery,
} from "graphql/operations-types"; } from "graphql/operations-types";
import { getAssetURL, prettySlug } from "queries/helpers"; import { getAssetURL, ImageQuality, prettySlug } from "queries/helpers";
import Image from "next/image"; import Image from "next/image";
import Button from "components/Button"; import Button from "components/Button";
@ -30,7 +30,7 @@ export default function ThumbnailHeader(
{content.thumbnail.data ? ( {content.thumbnail.data ? (
<Image <Image
className=" rounded-xl" className=" rounded-xl"
src={getAssetURL(content.thumbnail.data.attributes.url)} src={getAssetURL(content.thumbnail.data.attributes.url, ImageQuality.Medium)}
alt={content.thumbnail.data.attributes.alternativeText} alt={content.thumbnail.data.attributes.alternativeText}
width={content.thumbnail.data.attributes.width} width={content.thumbnail.data.attributes.width}
height={content.thumbnail.data.attributes.height} height={content.thumbnail.data.attributes.height}
@ -39,7 +39,7 @@ export default function ThumbnailHeader(
<div className="w-full aspect-[4/3] bg-light rounded-xl"></div> <div className="w-full aspect-[4/3] bg-light rounded-xl"></div>
)} )}
</div> </div>
<div className="grid place-items-center"> <div className="grid place-items-center text-center">
{content.titles.length > 0 ? ( {content.titles.length > 0 ? (
<> <>
<p className="text-2xl">{content.titles[0].pre_title}</p> <p className="text-2xl">{content.titles[0].pre_title}</p>

View File

@ -23,6 +23,7 @@ import {
prettyItemSubType, prettyItemSubType,
prettyPrice, prettyPrice,
prettySlug, prettySlug,
ImageQuality,
} from "queries/helpers"; } from "queries/helpers";
import SubPanel from "components/Panels/SubPanel"; import SubPanel from "components/Panels/SubPanel";
import ReturnButton from "components/PanelComponents/ReturnButton"; import ReturnButton from "components/PanelComponents/ReturnButton";
@ -113,7 +114,10 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
<div className="drop-shadow-dark-xl w-full h-[50vh] mobile:h-[80vh] mb-16 "> <div className="drop-shadow-dark-xl w-full h-[50vh] mobile:h-[80vh] mb-16 ">
{item.thumbnail.data ? ( {item.thumbnail.data ? (
<Image <Image
src={getAssetURL(item.thumbnail.data.attributes.url)} src={getAssetURL(
item.thumbnail.data.attributes.url,
ImageQuality.Medium
)}
alt={item.thumbnail.data.attributes.alternativeText} alt={item.thumbnail.data.attributes.alternativeText}
width={item.thumbnail.data.attributes.width} width={item.thumbnail.data.attributes.width}
height={item.thumbnail.data.attributes.height} height={item.thumbnail.data.attributes.height}
@ -186,10 +190,7 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
"" ""
)} )}
<InsetBox <InsetBox id="details" className="grid place-items-center">
id="details"
className="grid place-items-center"
>
<div className="w-[clamp(0px,100%,42rem)] grid place-items gap-8"> <div className="w-[clamp(0px,100%,42rem)] grid place-items gap-8">
<h2 className="text-2xl text-center"> <h2 className="text-2xl text-center">
{langui.library_item_details} {langui.library_item_details}

View File

@ -1,11 +1,20 @@
import { import {
GetLibraryItemQuery,
GetLibraryItemsPreviewQuery, GetLibraryItemsPreviewQuery,
GetWebsiteInterfaceQuery, GetWebsiteInterfaceQuery,
} from "graphql/operations-types"; } from "graphql/operations-types";
export function getAssetURL(url: string): string { export enum ImageQuality {
return process.env.NEXT_PUBLIC_URL_CMS + url; Small = "small",
Medium = "medium",
Large = "large"
}
export function getAssetURL(url: string, quality?: ImageQuality): string {
if (!quality) quality = ImageQuality.Small;
url = url.replace(/^\/uploads/, "/" + quality);
url = url.replace(/.jpg$/, ".webp");
url = url.replace(/.png$/, ".webp");
return process.env.NEXT_PUBLIC_URL_IMG + url;
} }
export function prettyDate( export function prettyDate(