Skip to content

Commit

Permalink
env variablkes and public paths
Browse files Browse the repository at this point in the history
  • Loading branch information
g4ze committed Oct 20, 2024
1 parent e212e4c commit bc132ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# for development only
NEXT_PUBLIC_PUBLIC_PATH=""
# for example public_path/assets/image.jpg
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# for production only
NEXT_PUBLIC_PUBLIC_PATH=https://gdg-oncampus-bu.github.io/landing-page-WIP/
8 changes: 4 additions & 4 deletions src/app/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import EventsSection from "@/components/EventsSection";
import Links from "@/components/Links";

export default function Home() {
const publicPath = process.env.NEXT_PUBLIC_PUBLIC_PATH ;
const [eventsData, setEventsData] = useState([]);

useEffect(() => {
const fetchEventsData = async () => {
const response = await fetch("/data/events.json");
const response = await fetch(publicPath+"/data/events.json");
const data = await response.json();
setEventsData(data);
};
Expand All @@ -30,15 +30,15 @@ export default function Home() {
}, 600);
}
};

return (
<>
<Navbar />

<div
className="flex flex-col items-center justify-center min-h-screen p-8 pb-20 gap-8 sm:p-20 text-center"
style={{
backgroundImage: `url('/assets/image1.png')`,
// we are hardcoding the image url here due to gh pages and next contraints
backgroundImage: `url('https://gdg-oncampus-bu.github.io/landing-page-WIP/assets/image1.png')`,
backgroundSize: "contain",
backgroundRepeat: "no-repeat",
backgroundPosition: "bottom",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useEffect, useState } from "react";
import Image from "next/image";
import gdg_logo from "../../public/assets/logo_gdg.png";

export default function Navbar() {
const public_path = process.env.NEXT_PUBLIC_PUBLIC_PATH
const [visible, setVisible] = useState(false);
const [scrollPosition, setScrollPosition] = useState(0);

Expand Down Expand Up @@ -36,7 +36,7 @@ export default function Navbar() {
className="flex items-center space-x-3 rtl:space-x-reverse"
>
<Image
src={gdg_logo}
src={public_path + "/assets/logo_gdg.png"}
alt="GDG Logo"
width={32}
height={32}
Expand Down

0 comments on commit bc132ac

Please sign in to comment.