Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace next image optimization with drupal image styles #93

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module.exports = {
hostname: drupalUrl.hostname,
},
],
deviceSizes: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me why you chose these breakpoints?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly arbitrary. I took the default values and commented out the ones I didn't want. I tried to get something close-ish to the breakpoints.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not align them with the breakpoints of the design system?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh, it's not really necessary IMO. Images don't need to break down at the same breakpoint. Just as long as the image is larger than the area it's in. Almost all images use a css cover property anyways

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a thing to ask what others on the team are doing and how they set up their responsive images. It is in the 'doesn't really matter' category but this seems like a good opportunity to engage and align with others.

320,
768,
1200,
2000,
],
loader: 'custom',
loaderFile: './src/components/patterns/elements/image-loader.tsx',
},
typescript: {
ignoreBuildErrors: process.env.CI !== 'true',
Expand Down Expand Up @@ -55,22 +63,5 @@ module.exports = {
permanent: true,
}
]
},
async rewrites() {
return {
beforeFiles: [
{
source: '/_next/image',
destination: '/_next/image?url=/no-image.png',
has: [{type: 'query', key: 'url', value: (`${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}.*`)}],
missing: [{type: 'query', key: 'url', value: '(.*itok=([\\w|-]+))'}]
},
{
source: '/_next/image',
destination: '/_next/image?url=:url',
has: [{type: 'query', key: 'url', value: '(?<url>.*[jpg|png|jpeg|gif]\?itok=([\\w|-]+)).*'}]
},
]
};
},
}
}
17 changes: 17 additions & 0 deletions src/components/patterns/elements/image-loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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: 9999999, s: 'breakpoint_2xl_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}`;
}
export default ImageLoader;
1 change: 1 addition & 0 deletions src/lib/libguides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const fetchLibGuides = async ({accountId, subjectId}: {
}

const guidesConfig = {
next: {revalidate: 1},
headers: {'Authorization': 'Bearer ' + token},
}

Expand Down
Loading