Skip to content

Commit 9ae5739

Browse files
committed
Added basePath Checking for Image URLs
1 parent 35319d6 commit 9ae5739

File tree

5 files changed

+87
-57
lines changed

5 files changed

+87
-57
lines changed

src/app/landscape/page.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import CategoryGallery from "@/components/CategoryGallery";
2+
import { withBasePath } from "@/lib/basePath";
23

34
const images = [
4-
{ src: "/photos/landscape/Golden_Gate.JPG", alt: "Golden Gate" },
5-
{ src: "/photos/landscape/IMG_6490.JPG", alt: "IMG 6490" },
6-
{ src: "/photos/landscape/IMG_6494.JPG", alt: "IMG 6494" },
7-
{ src: "/photos/landscape/IMG_6507.JPG", alt: "IMG 6507" },
8-
{ src: "/photos/landscape/Palace_Corner.JPG", alt: "Palace Corner" },
9-
{ src: "/photos/landscape/Palace_Fine_Arts.JPG", alt: "Palace Fine Arts" },
10-
{ src: "/photos/landscape/Temple.PNG", alt: "Temple" },
11-
{ src: "/photos/landscape/_DSC0343.PNG", alt: "DSC0343" },
12-
{ src: "/photos/landscape/_DSC0353.PNG", alt: "DSC0353" },
13-
{ src: "/photos/landscape/_DSC0375.PNG", alt: "DSC0375" },
14-
{ src: "/photos/landscape/_DSC0400.jpg", alt: "DSC0400" },
15-
{ src: "/photos/landscape/_DSC0406.PNG", alt: "DSC0406" },
16-
{ src: "/photos/landscape/_DSC0432.PNG", alt: "DSC0432" },
17-
{ src: "/photos/landscape/_DSC0433.PNG", alt: "DSC0433" },
18-
{ src: "/photos/landscape/_DSC0625.PNG", alt: "DSC0625" },
5+
{ src: withBasePath("/photos/landscape/Golden_Gate.JPG"), alt: "Golden Gate" },
6+
{ src: withBasePath("/photos/landscape/IMG_6490.JPG"), alt: "IMG 6490" },
7+
{ src: withBasePath("/photos/landscape/IMG_6494.JPG"), alt: "IMG 6494" },
8+
{ src: withBasePath("/photos/landscape/IMG_6507.JPG"), alt: "IMG 6507" },
9+
{ src: withBasePath("/photos/landscape/Palace_Corner.JPG"), alt: "Palace Corner" },
10+
{ src: withBasePath("/photos/landscape/Palace_Fine_Arts.JPG"), alt: "Palace Fine Arts" },
11+
{ src: withBasePath("/photos/landscape/Temple.PNG"), alt: "Temple" },
12+
{ src: withBasePath("/photos/landscape/_DSC0343.PNG"), alt: "DSC0343" },
13+
{ src: withBasePath("/photos/landscape/_DSC0353.PNG"), alt: "DSC0353" },
14+
{ src: withBasePath("/photos/landscape/_DSC0375.PNG"), alt: "DSC0375" },
15+
{ src: withBasePath("/photos/landscape/_DSC0400.jpg"), alt: "DSC0400" },
16+
{ src: withBasePath("/photos/landscape/_DSC0406.PNG"), alt: "DSC0406" },
17+
{ src: withBasePath("/photos/landscape/_DSC0432.PNG"), alt: "DSC0432" },
18+
{ src: withBasePath("/photos/landscape/_DSC0433.PNG"), alt: "DSC0433" },
19+
{ src: withBasePath("/photos/landscape/_DSC0625.PNG"), alt: "DSC0625" },
1920
];
2021

2122
export default function LandscapePage() {

src/app/nature/page.tsx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import CategoryGallery from "@/components/CategoryGallery";
2+
import { withBasePath } from "@/lib/basePath";
23

34
const images = [
4-
{ src: "/photos/nature/IMG_6486.JPG", alt: "IMG 6486" },
5-
{ src: "/photos/nature/IMG_6487.JPG", alt: "IMG 6487" },
6-
{ src: "/photos/nature/IMG_6488.JPG", alt: "IMG 6488" },
7-
{ src: "/photos/nature/IMG_6491.JPG", alt: "IMG 6491" },
8-
{ src: "/photos/nature/IMG_6492.JPG", alt: "IMG 6492" },
9-
{ src: "/photos/nature/IMG_6493.JPG", alt: "IMG 6493" },
10-
{ src: "/photos/nature/SF_Bird.jpg", alt: "SF Bird" },
11-
{ src: "/photos/nature/SF_Swimmer.JPG", alt: "SF Swimmer" },
12-
{ src: "/photos/nature/_DSC0450.JPEG", alt: "DSC0450" },
13-
{ src: "/photos/nature/_DSC0473.JPEG", alt: "DSC0473" },
14-
{ src: "/photos/nature/_DSC0535.JPEG", alt: "DSC0535" },
15-
{ src: "/photos/nature/_DSC0539.JPEG", alt: "DSC0539" },
16-
{ src: "/photos/nature/_DSC0543.JPEG", alt: "DSC0543" },
17-
{ src: "/photos/nature/_DSC0550.JPEG", alt: "DSC0550" },
18-
{ src: "/photos/nature/_DSC0609.JPEG", alt: "DSC0609" },
19-
{ src: "/photos/nature/_DSC0631.JPEG", alt: "DSC0631" },
20-
{ src: "/photos/nature/_DSC0638.JPEG", alt: "DSC0638" },
21-
{ src: "/photos/nature/_DSC0651.JPEG", alt: "DSC0651" },
22-
{ src: "/photos/nature/_DSC0737.JPEG", alt: "DSC0737" },
23-
{ src: "/photos/nature/_DSC0824.JPEG", alt: "DSC0824" },
5+
{ src: withBasePath("/photos/nature/IMG_6486.JPG"), alt: "IMG 6486" },
6+
{ src: withBasePath("/photos/nature/IMG_6487.JPG"), alt: "IMG 6487" },
7+
{ src: withBasePath("/photos/nature/IMG_6488.JPG"), alt: "IMG 6488" },
8+
{ src: withBasePath("/photos/nature/IMG_6491.JPG"), alt: "IMG 6491" },
9+
{ src: withBasePath("/photos/nature/IMG_6492.JPG"), alt: "IMG 6492" },
10+
{ src: withBasePath("/photos/nature/IMG_6493.JPG"), alt: "IMG 6493" },
11+
{ src: withBasePath("/photos/nature/SF_Bird.jpg"), alt: "SF Bird" },
12+
{ src: withBasePath("/photos/nature/SF_Swimmer.JPG"), alt: "SF Swimmer" },
13+
{ src: withBasePath("/photos/nature/_DSC0450.JPEG"), alt: "DSC0450" },
14+
{ src: withBasePath("/photos/nature/_DSC0473.JPEG"), alt: "DSC0473" },
15+
{ src: withBasePath("/photos/nature/_DSC0535.JPEG"), alt: "DSC0535" },
16+
{ src: withBasePath("/photos/nature/_DSC0539.JPEG"), alt: "DSC0539" },
17+
{ src: withBasePath("/photos/nature/_DSC0543.JPEG"), alt: "DSC0543" },
18+
{ src: withBasePath("/photos/nature/_DSC0550.JPEG"), alt: "DSC0550" },
19+
{ src: withBasePath("/photos/nature/_DSC0609.JPEG"), alt: "DSC0609" },
20+
{ src: withBasePath("/photos/nature/_DSC0631.JPEG"), alt: "DSC0631" },
21+
{ src: withBasePath("/photos/nature/_DSC0638.JPEG"), alt: "DSC0638" },
22+
{ src: withBasePath("/photos/nature/_DSC0651.JPEG"), alt: "DSC0651" },
23+
{ src: withBasePath("/photos/nature/_DSC0737.JPEG"), alt: "DSC0737" },
24+
{ src: withBasePath("/photos/nature/_DSC0824.JPEG"), alt: "DSC0824" },
2425
];
2526

2627
export default function NaturePage() {

src/app/page.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import Link from "next/link";
44
import { useEffect, useMemo, useRef, useState } from "react";
5+
import { withBasePath } from "@/lib/basePath";
56

67
type Photo = {
78
category: "Landscape" | "Nature" | "Street";
@@ -12,27 +13,27 @@ type Photo = {
1213
const photos: Photo[] = [
1314
{
1415
category: "Landscape",
15-
src: "/photos/Bridge.png",
16+
src: withBasePath("/photos/Bridge.png"),
1617
featured: true
1718
},
1819
{
1920
category: "Nature",
20-
src: "/photos/Butterfly.png",
21+
src: withBasePath("/photos/Butterfly.png"),
2122
featured: true
2223
},
2324
{
2425
category: "Landscape",
25-
src: "/photos/Dreamy_Subway.png",
26+
src: withBasePath("/photos/Dreamy_Subway.PNG"),
2627
featured: true
2728
},
2829
{
2930
category: "Street",
30-
src: "/photos/SF_House.png",
31+
src: withBasePath("/photos/SF_House.PNG"),
3132
featured: true
3233
},
3334
{
3435
category: "Landscape",
35-
src: "/photos/Windmill.png",
36+
src: withBasePath("/photos/Windmill.png"),
3637
featured: true
3738
},
3839
];

src/app/street/page.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import CategoryGallery from "@/components/CategoryGallery";
2+
import { withBasePath } from "@/lib/basePath";
23

34
const images = [
4-
{ src: "/photos/street/Phone_Booth.JPG", alt: "Phone Booth" },
5-
{ src: "/photos/street/_DSC0354.PNG", alt: "DSC0354" },
6-
{ src: "/photos/street/_DSC0502.PNG", alt: "DSC0502" },
7-
{ src: "/photos/street/_DSC0514.PNG", alt: "DSC0514" },
8-
{ src: "/photos/street/_DSC0929.JPG", alt: "DSC0929" },
9-
{ src: "/photos/street/_DSC0964.JPG", alt: "DSC0964" },
10-
{ src: "/photos/street/_DSC0974.JPG", alt: "DSC0974" },
11-
{ src: "/photos/street/_DSC0977.JPG", alt: "DSC0977" },
12-
{ src: "/photos/street/_DSC1026.jpg", alt: "DSC1026" },
13-
{ src: "/photos/street/_DSC1029.JPG", alt: "DSC1029" },
14-
{ src: "/photos/street/_DSC1059.jpg", alt: "DSC1059" },
15-
{ src: "/photos/street/_DSC1060.JPG", alt: "DSC1060" },
16-
{ src: "/photos/street/_DSC1068.JPG", alt: "DSC1068" },
17-
{ src: "/photos/street/_DSC1081.JPG", alt: "DSC1081" },
18-
{ src: "/photos/street/_DSC1084.JPG", alt: "DSC1084" },
19-
{ src: "/photos/street/_DSC1107.JPG", alt: "DSC1107" },
20-
{ src: "/photos/street/_DSC1117.JPG", alt: "DSC1117" },
5+
{ src: withBasePath("/photos/street/Phone_Booth.JPG"), alt: "Phone Booth" },
6+
{ src: withBasePath("/photos/street/_DSC0354.PNG"), alt: "DSC0354" },
7+
{ src: withBasePath("/photos/street/_DSC0502.PNG"), alt: "DSC0502" },
8+
{ src: withBasePath("/photos/street/_DSC0514.PNG"), alt: "DSC0514" },
9+
{ src: withBasePath("/photos/street/_DSC0929.JPG"), alt: "DSC0929" },
10+
{ src: withBasePath("/photos/street/_DSC0964.JPG"), alt: "DSC0964" },
11+
{ src: withBasePath("/photos/street/_DSC0974.JPG"), alt: "DSC0974" },
12+
{ src: withBasePath("/photos/street/_DSC0977.JPG"), alt: "DSC0977" },
13+
{ src: withBasePath("/photos/street/_DSC1026.jpg"), alt: "DSC1026" },
14+
{ src: withBasePath("/photos/street/_DSC1029.JPG"), alt: "DSC1029" },
15+
{ src: withBasePath("/photos/street/_DSC1059.jpg"), alt: "DSC1059" },
16+
{ src: withBasePath("/photos/street/_DSC1060.JPG"), alt: "DSC1060" },
17+
{ src: withBasePath("/photos/street/_DSC1068.JPG"), alt: "DSC1068" },
18+
{ src: withBasePath("/photos/street/_DSC1081.JPG"), alt: "DSC1081" },
19+
{ src: withBasePath("/photos/street/_DSC1084.JPG"), alt: "DSC1084" },
20+
{ src: withBasePath("/photos/street/_DSC1107.JPG"), alt: "DSC1107" },
21+
{ src: withBasePath("/photos/street/_DSC1117.JPG"), alt: "DSC1117" },
2122
];
2223

2324
export default function StreetPage() {

src/lib/basePath.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
2+
3+
export const withBasePath = (path: string) => {
4+
if (!path) {
5+
return path;
6+
}
7+
8+
if (path.startsWith("http://") || path.startsWith("https://")) {
9+
return path;
10+
}
11+
12+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
13+
14+
if (!BASE_PATH) {
15+
return normalizedPath;
16+
}
17+
18+
if (
19+
normalizedPath === BASE_PATH ||
20+
normalizedPath.startsWith(`${BASE_PATH}/`)
21+
) {
22+
return normalizedPath;
23+
}
24+
25+
return `${BASE_PATH}${normalizedPath}`;
26+
};

0 commit comments

Comments
 (0)