Skip to content

Commit 4fc0289

Browse files
committed
Optimize Netlify deployments and bust image caches
1 parent 475dc70 commit 4fc0289

5 files changed

Lines changed: 39 additions & 24 deletions

File tree

.github/workflows/deploy-to-netlify.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: Deploy to Netlify
22

33
on:
4-
push:
5-
branches: [main]
6-
paths-ignore:
7-
- "functions/**"
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: netlify-production-${{ github.repository }}
8+
cancel-in-progress: true
89

910
permissions:
1011
contents: read
@@ -34,8 +35,13 @@ jobs:
3435
- name: Install dependencies
3536
run: bun install
3637

37-
- name: Build project
38-
run: bun run build
38+
- name: Cache Next.js build
39+
uses: actions/cache@v4
40+
with:
41+
path: .next/cache
42+
key: ${{ runner.os }}-nextjs-${{ hashFiles('bun.lockb', 'package-lock.json') }}
43+
restore-keys: |
44+
${{ runner.os }}-nextjs-
3945
4046
# Use npm for netlify-cli installation instead of bun
4147
- name: Install Netlify CLI
@@ -47,10 +53,3 @@ jobs:
4753
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
4854
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
4955
NEXT_PUBLIC_NETLIFY: "true" # Optional but recommended
50-
51-
- name: Cache Next.js build
52-
uses: actions/cache@v3
53-
with:
54-
path: |
55-
.next/cache
56-
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}

app/admin/articles/[id]/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@ export default function EditArticlePage() {
121121
const { storage } = await import("@/lib/firebase");
122122

123123
const storageRef = ref(storage, `Articles/${id}/thumbnail.webp`);
124-
await uploadBytes(storageRef, thumbnailFile);
124+
await uploadBytes(storageRef, thumbnailFile, {
125+
contentType: "image/webp",
126+
cacheControl: "public,max-age=300",
127+
});
125128
const url = await getDownloadURL(storageRef);
126129

127-
setImg(url);
130+
const versionedURL = `${url}${url.includes("?") ? "&" : "?"}v=${Date.now()}`;
131+
setImg(versionedURL);
128132
const newAlt = `${title || "Article"} thumbnail`;
129133
setImgAlt(newAlt);
130134
toast({ title: "Thumbnail uploaded", variant: "success" });

app/admin/articles/new/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ export default function NewArticlePage() {
118118
const { storage } = await import("@/lib/firebase");
119119

120120
const storageRef = ref(storage, `Articles/${articleId}/thumbnail.webp`);
121-
await uploadBytes(storageRef, thumbnailFile);
121+
await uploadBytes(storageRef, thumbnailFile, {
122+
contentType: "image/webp",
123+
cacheControl: "public,max-age=300",
124+
});
122125
const url = await getDownloadURL(storageRef);
123126

124-
setImg(url);
127+
const versionedURL = `${url}${url.includes("?") ? "&" : "?"}v=${Date.now()}`;
128+
setImg(versionedURL);
125129
const newAlt = `${title || "Article"} thumbnail`;
126130
setImgAlt(newAlt);
127131
toast({ title: "Thumbnail uploaded", variant: "success" });

app/admin/profile/page.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,18 @@ export default function ProfilePage() {
427427
setUploadingAvatar(true)
428428
try {
429429
const storageRef = ref(storage, `avatars/team/${auth.currentUser.uid}.webp`)
430-
const uploadTask = await uploadBytes(storageRef, croppedBlob)
430+
const uploadTask = await uploadBytes(storageRef, croppedBlob, {
431+
contentType: "image/webp",
432+
cacheControl: "public,max-age=300",
433+
})
431434
const downloadURL = await getDownloadURL(uploadTask.ref)
435+
const versionedURL = `${downloadURL}${downloadURL.includes("?") ? "&" : "?"}v=${Date.now()}`
432436

433-
setProfile((prev) => ({ ...prev, avatar: downloadURL }))
437+
setProfile((prev) => ({ ...prev, avatar: versionedURL }))
434438

435439
// Auto-save the profile with new avatar
436440
const userRef = doc(db, "authors", auth.currentUser.uid)
437-
await updateDoc(userRef, { avatar: downloadURL })
441+
await updateDoc(userRef, { avatar: versionedURL })
438442

439443
toast({
440444
title: "Avatar updated",

app/admin/team/[id]/page.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,26 @@ export default function EditTeamMemberPage() {
305305
.replace(/(^-|-$)+/g, "") || "unknown-member";
306306

307307
const storageRef = ref(storage, `avatars/team/${nameSlug}.webp`);
308-
const uploadTask = await uploadBytes(storageRef, croppedBlob);
308+
const uploadTask = await uploadBytes(storageRef, croppedBlob, {
309+
contentType: "image/webp",
310+
cacheControl: "public,max-age=300",
311+
});
309312
const downloadURL = await getDownloadURL(uploadTask.ref);
313+
const versionedURL = `${downloadURL}${downloadURL.includes("?") ? "&" : "?"}v=${Date.now()}`;
310314

311315
const newImgAlt = `${member.name} profile pic, a member of L.A.P`;
312316

313317
// Update local state
314318
setMember((prev) =>
315-
prev ? { ...prev, avatar: downloadURL, imgAlt: newImgAlt } : null,
319+
prev ? { ...prev, avatar: versionedURL, imgAlt: newImgAlt } : null,
316320
);
317-
setAvatarPreview(downloadURL);
321+
setAvatarPreview(versionedURL);
318322

319323
// Auto-save to Firestore
320324
if (id) {
321325
const ref = doc(db, "authors", id);
322326
await updateDoc(ref, {
323-
avatar: downloadURL,
327+
avatar: versionedURL,
324328
imgAlt: newImgAlt,
325329
});
326330
}

0 commit comments

Comments
 (0)