Skip to content

Commit

Permalink
[feat] Add env.mjs (#9)
Browse files Browse the repository at this point in the history
* Add env.mjs

* Fix base path
  • Loading branch information
adityapawar1 authored Jan 17, 2025
1 parent e897c6a commit 1bb9e21
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Build Next.js app
on:
pull_request:

env:
NEXT_PUBLIC_BASE_PATH: /${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ concurrency:
cancel-in-progress: false

env:
BASE_PATH: ${{ github.repository }}
NEXT_PUBLIC_BASE_PATH: ${{ github.repository }}

jobs:
# Build job
Expand Down
3 changes: 2 additions & 1 deletion app/(default-layout)/projects/[name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Link from 'next/link';
import { ProjectData } from '@/app/(hero-layout)/projects/page';
import ProjectDescription from '@/components/ProjectDescription/ProjectDescription';
import projects from '@/data/projects.json';
import { env } from '@/env.mjs';

type ProjectDetailsPageProps = {
params: Promise<{ name: string }>;
Expand All @@ -24,7 +25,7 @@ export default async function ProjectDetailsPage({
const data = projectList[name as keyof typeof projectList] as ProjectData;
let imageSrc = data.banner_image;
if (!data.banner_image.includes('http')) {
imageSrc = '/' + data.banner_image;
imageSrc = env.NEXT_PUBLIC_BASE_PATH + data.banner_image;
}

return (
Expand Down
3 changes: 2 additions & 1 deletion app/(hero-layout)/chapters/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import HeroButton from '@/components/HeroButton/HeroButton';
import PageNav from '@/components/PageNav/PageNav';
import chapters from '@/data/chapters.json';
import externalLinks from '@/data/external_links.json';
import { env } from '@/env.mjs';
import impactImage from '@/public/images/apply/nonprofits/impact.png';
import cultureImage from '@/public/images/apply/students/culture.png';
import growthImage from '@/public/images/apply/students/growth.png';
Expand Down Expand Up @@ -61,7 +62,7 @@ export default function ChapterPage() {
<Image
sizes="100vw"
fill
src={'/' + chapter.image}
src={env.NEXT_PUBLIC_BASE_PATH + chapter.image}
alt={chapter.name}
objectFit="cover"
/>
Expand Down
3 changes: 2 additions & 1 deletion app/(hero-layout)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Link from 'next/link';
import CenteredHero from '@/components/Hero/CenteredHero';
import HeroButton from '@/components/HeroButton/HeroButton';
import projects from '@/data/projects.json';
import { env } from '@/env.mjs';
import bidsImage from '@/public/images/home/bids.png';
import groupPhoto from '@/public/images/home/group_photo_2024.jpg';
import nibImage from '@/public/images/home/nib.png';
Expand Down Expand Up @@ -87,7 +88,7 @@ export default function HomePage() {
<div className="project-img img-container">
<Image
alt={projectData.title}
src={'/' + projectData.banner_image}
src={env.NEXT_PUBLIC_BASE_PATH + projectData.banner_image}
fill
/>
</div>
Expand Down
3 changes: 2 additions & 1 deletion components/ProjectCard/ProjectCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Image from 'next/image';
import Link from 'next/link';
import { env } from '@/env.mjs';

type ProjectCardProps = {
name: string;
Expand All @@ -18,7 +19,7 @@ export default async function ProjectCard({
}: ProjectCardProps) {
let imageSrc = banner_image;
if (!banner_image.includes('http')) {
imageSrc = '/' + banner_image;
imageSrc = env.NEXT_PUBLIC_BASE_PATH + banner_image;
}

return (
Expand Down
8 changes: 8 additions & 0 deletions env.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
client: {
NEXT_PUBLIC_BASE_PATH: z.string().default(''),
},
});
2 changes: 1 addition & 1 deletion next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
basePath: '/' + (process.env.BASE_PATH || 'calblueprint.org.v2'),
basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
images: {
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
Expand Down
48 changes: 46 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
"@t3-oss/env-nextjs": "^0.11.1",
"bootstrap": "^5.3.3",
"crypto-js": "^4.2.0",
"next": "15.1.4",
Expand All @@ -19,7 +20,8 @@
"react-dom": "^19.0.0",
"react-icons": "^5.4.0",
"react-markdown": "^9.0.3",
"sass": "^1.83.4"
"sass": "^1.83.4",
"zod": "^3.24.1"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
Expand Down
42 changes: 42 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1bb9e21

Please sign in to comment.