Skip to content

Commit

Permalink
Fixup styles
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Dec 12, 2023
1 parent 7168175 commit c96af7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
22 changes: 4 additions & 18 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,13 @@ module.exports = {
},
],
deviceSizes: [
// 640,
750,
// 828,
// 1080,
320,
768,
1200,
// 1920,
// 2048,
3840
],
imageSizes: [
// 16,
// 32,
// 48,
// 64,
// 96,
128,
// 256,
384
2000,
],
loader: 'custom',
loaderFile: './components/patterns/elements/image-loader.tsx',
loaderFile: './src/components/patterns/elements/image-loader.tsx',
},
typescript: {
ignoreBuildErrors: process.env.CI !== 'true',
Expand Down
8 changes: 5 additions & 3 deletions src/components/patterns/elements/image-loader.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const ImageLoader = ({ src, width }) => {
const ImageLoader = ({src, width}: { src: string, width: number }) => {
const imageStyles = [
{w: 128, s: 'breakpoint_sm_2x'},
{w: 384, s: 'breakpoint_md_2x'},
{w: 400, s: 'breakpoint_md_2x'},
{w: 750, s: 'breakpoint_lg_2x'},
{w: 1200, s: 'breakpoint_xl_2x'},
{w: 3840, s: 'breakpoint_2xl_2x'},
{w: 9999999, s: 'breakpoint_2xl_2x'},
];
const style = imageStyles.find(s => s.w === width)?.s || 'breakpoint_xl_2x';
// Find the first image style that is larger than the desired width.
const style = imageStyles.find(s => s.w >= width)?.s;

// Switch the image style for the desired width. Add the width parameter just to prevent console logs.
// https://nextjs.org/docs/messages/next-image-missing-loader-width
return src.toString().replace(/styles\/\w+\//, `styles/${style}/`) + `&w=${width}`;
Expand Down

0 comments on commit c96af7a

Please sign in to comment.