Skip to content

Commit

Permalink
Merge pull request #25 from tlenclos/feature/image-optimization
Browse files Browse the repository at this point in the history
Image optimization
  • Loading branch information
tlenclos authored Jan 31, 2023
2 parents 2dc4e71 + dfe7801 commit d1a2de6
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 11 deletions.
26 changes: 20 additions & 6 deletions app/components/Place.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import {
CheckCircleIcon,
CloseIcon,
LinkIcon,
WarningIcon,
} from "@chakra-ui/icons";
import {
Box,
Heading,
HStack,
Image,
Link,
List,
ListItem,
Expand All @@ -26,6 +24,7 @@ import {
WrapItem,
} from "@chakra-ui/react";
import { useState } from "react";
import Image, { MimeType } from "remix-image";
import type { Place as PlaceType } from "~/lib/fetchPlaces";
import PhotoSlider from "./PhotoSlider";

Expand Down Expand Up @@ -152,11 +151,26 @@ export default function Place({ data: place, toggleFilter }: Props) {
.slice(0, isDesktop ? 2 : 2)
.map((photo, photoIndex) => (
<Image
src={`images/${photo}`}
key={photo}
boxSize={["100%", "200px"]}
objectFit="cover"
border="solid 2px lightgray"
src={`images/${photo}`}
responsive={[
{
size: {
width: 170,
height: 170,
},
maxWidth: 170,
},
]}
options={{
fit: "cover",
contentType: MimeType.WEBP,
quality: 80,
}}
style={{
objectFit: "cover",
border: "solid 2px lightgray",
}}
onClick={() => setSelectedPhoto(photoIndex)}
/>
))}
Expand Down
2 changes: 2 additions & 0 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ScrollRestoration,
} from "@remix-run/react";
import { MetaFunction, LinksFunction } from "@remix-run/node"; // Depends on the runtime you choose
import remixImageStyles from "remix-image/remix-image.css";

import { ServerStyleContext, ClientStyleContext } from "./context";

Expand All @@ -21,6 +22,7 @@ export const meta: MetaFunction = () => ({

export let links: LinksFunction = () => {
return [
{ rel: "stylesheet", href: remixImageStyles },
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
{ rel: "preconnect", href: "https://fonts.gstatic.com" },
{
Expand Down
17 changes: 17 additions & 0 deletions app/routes/api/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { LoaderFunction } from "@remix-run/server-runtime";
import { imageLoader, LoaderConfig, MemoryCache } from "remix-image/server";
import { sharpTransformer } from "remix-image-sharp";

const config: LoaderConfig = {
selfUrl:
process.env.NODE_ENV === "development"
? "http://localhost:3001"
: "https://joli-mapstr.vercel.app/",
transformer: sharpTransformer,
cache: new MemoryCache(),
redirectOnFail: true,
};

export const loader: LoaderFunction = ({ request }) => {
return imageLoader(config, request);
};
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@emotion/react": "^11",
"@emotion/server": "^11",
"@emotion/styled": "^11",
"@next-boost/hybrid-disk-cache": "^0.3.0",
"@remix-run/dev": "^1.11.1",
"@remix-run/eslint-config": "^1.11.1",
"@remix-run/node": "^1.11.1",
Expand All @@ -23,6 +24,9 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.7.1",
"remix-image": "^1.4.0",
"remix-image-sharp": "^0.1.4",
"sharp": "^0.31.3",
"swiper": "^8.3.2"
},
"devDependencies": {
Expand Down
Loading

1 comment on commit d1a2de6

@vercel
Copy link

@vercel vercel bot commented on d1a2de6 Jan 31, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

joli-mapstr – ./

joli-mapstr-tlenclos.vercel.app
joli-mapstr-git-master-tlenclos.vercel.app
joli-mapstr.vercel.app

Please sign in to comment.