Skip to content

Commit 85e1216

Browse files
committed
Optimize template images + disable image optim docker
1 parent 2274bd1 commit 85e1216

File tree

9 files changed

+42
-10
lines changed

9 files changed

+42
-10
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ADD client/package.json client/package-lock.json ./
1414
RUN npm install
1515

1616
ADD client /app/
17+
RUN cp .env.docker .env
1718
RUN npm run build
1819

1920
# syntax=docker/dockerfile:1.3-labs

client/.env.docker

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ NUXT_PUBLIC_GOOGLE_ANALYTICS_CODE=
1010
NUXT_PUBLIC_H_CAPTCHA_SITE_KEY=
1111
NUXT_PUBLIC_PAID_PLANS_ENABLED=false
1212
NUXT_PUBLIC_S3_ENABLED=false
13+
NUXT_PUBLIC_DISABLE_IMAGE_OPTIMIZATION=true
1314
NUXT_API_SECRET=

client/components/pages/templates/SingleTemplate.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
</div>
1818

1919
<div class="aspect-[4/3] rounded-lg shadow-sm overflow-hidden">
20-
<img class="group-hover:scale-110 transition-all duration-200 h-full object-cover w-full"
21-
:src="template.image_url" alt=""
20+
<NuxtImg class="group-hover:scale-110 transition-all duration-200 h-full object-cover w-full" v-if="template.image_url"
21+
:src="template.image_url" alt="" width="450px"
2222
/>
2323
</div>
2424
<p
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { joinURL } from 'ufo'
2+
import { createOperationsGenerator } from '#image'
3+
4+
const operationsGenerator = createOperationsGenerator()
5+
6+
export const getImage = (
7+
src,
8+
{ modifiers = {}, baseURL } = {}
9+
) => {
10+
11+
if (!baseURL) {
12+
// also support runtime config
13+
baseURL = useRuntimeConfig().public.siteUrl
14+
}
15+
16+
const operations = operationsGenerator(modifiers)
17+
18+
return {
19+
url: joinURL(baseURL, src + (operations ? '?' + operations : '')),
20+
}
21+
}

client/nuxt.config.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,17 @@ export default defineNuxtConfig({
6464
}
6565
}
6666
},
67-
image: {
67+
image: runtimeConfig.public.useDummyImageProvider ? {
68+
provider: 'dummy',
69+
providers: {
70+
dummy: {
71+
provider: '~/lib/dummy-image-provider.js',
72+
}
73+
}
74+
} :{
6875
quality: 95,
76+
format: 'webp',
77+
domains: ['images.unsplash.com']
6978
},
7079
sourcemap: true,
7180
vite: {

client/pages/templates/[slug].vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
<section class="pt-12 bg-gray-50 sm:pt-16 border-b pb-[250px] relative">
3333
<div class="px-4 mx-auto sm:px-6 lg:px-8 max-w-7xl">
3434
<div class="flex flex-col items-center justify-center max-w-4xl gap-8 mx-auto md:gap-12 md:flex-row">
35-
<div class="aspect-[4/3] shrink-0 rounded-lg shadow-sm overflow-hidden group max-w-xs">
36-
<img class="object-cover w-full h-full transition-all duration-200 group-hover:scale-110"
37-
:src="template.image_url" alt="Template cover image"
35+
<div class="aspect-[4/3] shrink-0 rounded-lg shadow-sm overflow-hidden group max-w-sm">
36+
<NuxtImg class="object-cover w-full transition-all duration-200 group-hover:scale-110 h-[240px]"
37+
:src="template.image_url" alt="Template cover image" width="500px" height="380px"
3838
/>
3939
</div>
4040

client/pages/templates/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import {loadAllTemplates} from "~/stores/templates.js";
2424
2525
defineRouteRules({
26-
swr: 3600
26+
// swr: 3600
2727
})
2828
2929
useOpnSeoMeta({

client/runtimeConfig.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default {
1212
s3Enabled: process.env.NUXT_PUBLIC_S3_ENABLED || false,
1313
paidPlansEnabled: process.env.NUXT_PUBLIC_PAID_PLANS_ENABLED || false,
1414
customDomainsEnabled: process.env.NUXT_PUBLIC_CUSTOM_DOMAINS_ENABLED || false,
15+
useDummyImageProvider: process.env.NUXT_PUBLIC_IMAGE_OPTIMIZATION_DISABLED || false,
1516

1617
// Config within public will be also exposed to the client
1718
SENTRY_DSN_PUBLIC: process.env.SENTRY_DSN_PUBLIC,

docker/nuxt-wrapper.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ nvm use 20
77
cd /app/nuxt/server/
88

99
. /app/client/.env
10-
[ "x$NUXT_API_SECRET" != "x" ] || generate-api-secret.sh
1110

12-
sed 's/^/export /' < /app/.nuxt.env > env.sh
11+
[ "x$NUXT_API_SECRET" != "x" ] || generate-api-secret.sh
1312

14-
. env.sh
13+
eval $(sed 's/^/export /' < /app/client/.env)
1514

1615
node index.mjs

0 commit comments

Comments
 (0)