Skip to content

Commit 7110541

Browse files
authored
Upcoming events section added! (#21)
* feat: upcoming events section * fix: cta bg and events fetch from official repo events.json file * fix: changed the events url to be imported from config * fix: project structure change in semicolon at eol
1 parent bf92b00 commit 7110541

File tree

7 files changed

+131
-26
lines changed

7 files changed

+131
-26
lines changed

config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ featured:
4646
- "2021/satyarajawasth1" # slug
4747
blogs:
4848
- "2017/ncit-alumni-reflections"
49+
50+
events:
51+
upcoming:
52+
title: Upcoming Events
53+
link: "https://raw.githubusercontent.com/noskofficial/noskofficial.github.io/main/events.json"

public/event.jpg

178 KB
Loading

src/components/homepage/JoinCTA.astro

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<section class="w-full flex-col justify-start items-center bg-gray-700 text-white py-8">
1+
<section class="w-full flex-col justify-start items-center bg-gray-800 text-white py-8">
22
<div class="text-center mb-12">
33
<h2 class="text-3xl md:text-5xl font-bold my-4 mx-4 sm:mx-8">
44
Join Our Open Source Movement
@@ -16,8 +16,5 @@
1616
Learn More
1717
</a>
1818
</div>
19-
<p class="text-lg md:text-xl pt-8 mx-4 sm:mx-8">
20-
A Call To Action!
21-
</p>
2219
</div>
2320
</section>
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
import { loadConfig } from "../../utils/loadconfig";
3+
import { EventData } from "../../utils/types";
4+
5+
const config = loadConfig();
6+
const upcoming_event_link = config.events.upcoming.link;
7+
8+
let eventsData: EventData[];
9+
try {
10+
const response = await fetch(upcoming_event_link);
11+
if (!response.ok) {
12+
throw new Error(`HTTP error! status: ${response.status}`);
13+
}
14+
eventsData = await response.json();
15+
eventsData.forEach((event, index) => {
16+
if (!event.BannerURL) {
17+
event.BannerURL = "event.jpg";
18+
}
19+
});
20+
21+
} catch (error) {
22+
console.error('Error fetching events:', error);
23+
eventsData = [];
24+
}
25+
---
26+
<section class="w-full flex-col justify-start items-center bg-gray-900 text-white py-16">
27+
<div class="text-center mb-12">
28+
<h2 class="text-3xl md:text-5xl font-bold mb-4 mx-4 sm:mx-8">
29+
Upcoming Events
30+
</h2>
31+
<p class="text-lg md:text-xl mb-10 mx-4 sm:mx-8">
32+
Stay updated with the latest events and gatherings happening soon. Don't miss out on the action!
33+
</p>
34+
</div>
35+
36+
<div class="flex-row items-center py-5">
37+
<div class="grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 gap-6 mx-6 lg:mx-16">
38+
{eventsData.slice(0,2).map(({ Title, By, Date, Time, URL, BannerURL }) => (
39+
<div class="bg-gray-800 rounded-lg p-6 shadow-lg flex flex-col md:flex-row justify-between items-center h-full">
40+
<div class="flex flex-col justify-between flex-1 mb-4 md:mb-0 md:mr-6 h-full">
41+
<div>
42+
<h3 class="text-2xl font-semibold text-lime-300 mb-2">{Title}</h3>
43+
<div class="flex items-center text-lg font-medium mb-2">
44+
<span class="text-lime-300">{Date}</span>
45+
<span class="mx-2">|</span>
46+
<span class="text-gray-400">{Time}</span>
47+
</div>
48+
{/* By: */}
49+
{
50+
By.map((by) => (
51+
<p class="mb-4 text-lg text-gray-300">
52+
{by}
53+
</p>
54+
))
55+
}
56+
57+
</div>
58+
<div class="mt-auto">
59+
<a
60+
href={URL}
61+
class="border border-yellow-500 hover:bg-yellow-500 text-white py-1 px-2 transition-all duration-300">
62+
Learn More
63+
</a>
64+
</div>
65+
</div>
66+
<div class="w-full md:w-1/3 h-auto">
67+
<img class="w-full h-auto rounded-md" src={BannerURL} alt="Event image" />
68+
</div>
69+
</div>
70+
))}
71+
</div>
72+
</div>
73+
74+
<div class="text-center mt-12">
75+
<a href="/events" class="border border-green-500 hover:bg-green-500 text-white py-3 px-6 transition-all duration-300">
76+
View More Events
77+
</a>
78+
</div>
79+
</section>

src/layout/HomeLayout.astro

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import TopNavigation from "../components/shared/TopNavigation.astro"
33
import HeroSection from '../components/homepage/HeroSection.astro';
44
import ProfileHighlight from '../components/homepage/ProfileHighlight.astro';
55
import BlogHighlight from '../components/homepage/BlogHighlight.astro';
6+
import UpEvents from "../components/homepage/UpEvents.astro";
67
import JoinCTA from '../components/homepage/JoinCTA.astro';
78
import Footer from '../components/shared/Footer.astro';
89
@@ -15,6 +16,7 @@ const { children } = Astro.props;
1516
<HeroSection />
1617
<ProfileHighlight />
1718
<BlogHighlight />
19+
<UpEvents />
1820
<JoinCTA />
1921
<Footer />
2022

src/utils/loadconfig.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
import fs from "fs";
2-
import path from "path";
3-
import yaml from "js-yaml";
4-
import { getCollection } from 'astro:content';
1+
import fs from "fs"
2+
import path from "path"
3+
import yaml from "js-yaml"
4+
import { getCollection } from "astro:content"
55

66
export interface Root {
77
menu: Menu
88
featured: FeaturedDetails
99
footer: Footer
10+
events: Event
11+
}
12+
13+
export interface Event {
14+
upcoming: Upcoming
15+
}
16+
17+
export interface Upcoming {
18+
title: string
19+
link: string
1020
}
1121

1222
export interface Menu {
@@ -35,19 +45,19 @@ export interface SubMenu {
3545
}
3646

3747
interface FeaturedDetails {
38-
profiles: string[];
39-
blogs: string[];
48+
profiles: string[]
49+
blogs: string[]
4050
}
4151

4252
export function loadConfig(): Root {
43-
const filePath = path.resolve("./config.yml");
44-
const fileContents = fs.readFileSync(filePath, "utf8");
45-
return yaml.load(fileContents) as Root;
53+
const filePath = path.resolve("./config.yml")
54+
const fileContents = fs.readFileSync(filePath, "utf8")
55+
return yaml.load(fileContents) as Root
4656
}
4757

4858
export const getFeaturedProfiles = async (paths: string[]) => {
49-
const allProfiles = await getCollection('profiles');
50-
59+
const allProfiles = await getCollection("profiles")
60+
5161
// Filter profiles based on featured.profiles in the config.yml file
52-
return allProfiles.filter(profile => paths.includes(profile.slug));
53-
};
62+
return allProfiles.filter((profile) => paths.includes(profile.slug))
63+
}

src/utils/types.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
export interface AlumniProfileInfo {
2-
name: string;
3-
program: string;
4-
batch: string;
5-
image?: { url: string };
6-
slogan?: string;
7-
tags: string[];
8-
history: { year: string; position: string; company: string }[];
9-
slug: string;
10-
}
2+
name: string
3+
program: string
4+
batch: string
5+
image?: { url: string }
6+
slogan?: string
7+
tags: string[]
8+
history: { year: string; position: string; company: string }[]
9+
slug: string
10+
}
11+
12+
export interface EventData {
13+
id: string
14+
Title: string
15+
By: string[]
16+
Date: string
17+
Time: string
18+
URL: string
19+
IMGURL: string // this is the url to the section on html page so it cannot be used for the image
20+
BannerURL: string // there is no banner url but should be added for latest entries to the events.json
21+
ProfileLink: string[]
22+
}

0 commit comments

Comments
 (0)