|
| 1 | +import Image from "next/image"; |
| 2 | +import LandingPageContent from "@/components/LandingPageContent/LandingPageContent"; |
| 3 | +import navbar from "@/assets/navbar.svg"; |
| 4 | +import OldSponsorships from "@/components/SponsorshipsSection/Sponsorships"; |
| 5 | +import { Metadata } from "next"; |
| 6 | +import { ItemList, WithContext } from "schema-dts"; |
| 7 | +import { get } from "@/utils/request"; |
| 8 | +import { Course, Courses } from "@/types/api"; |
| 9 | +import NewSponsorships from "@/components/SponsorshipsSection/NewSponsorships"; |
| 10 | +import Header from "./Header"; |
| 11 | +import Features from "./Features"; |
| 12 | + |
| 13 | +// Metadata to assist SEO - provies metadata for HTML head section |
| 14 | +export async function generateMetadata(): Promise<Metadata> { |
| 15 | + return { |
| 16 | + title: `Home | Unilectives - UNSW Course Reviews`, |
| 17 | + description: `UNSW course reviews, ratings, and study tips. Unilectives is your one-stop shop for making informed course choices at UNSW.`, |
| 18 | + }; |
| 19 | +} |
| 20 | + |
| 21 | +export default async function LandingPage() { |
| 22 | + // GET request for all courses |
| 23 | + const { courses: initialCourses } = (await get( |
| 24 | + "/courses?offset=0", |
| 25 | + )) as Courses; |
| 26 | + |
| 27 | + // Generate metadata to help with SEO (inject via script in return) |
| 28 | + const metaLD: WithContext<ItemList> = { |
| 29 | + "@context": "https://schema.org", |
| 30 | + "@type": "ItemList", |
| 31 | + itemListElement: initialCourses.map((course: Course, index: number) => ({ |
| 32 | + "@type": "ListItem", |
| 33 | + position: index + 1, |
| 34 | + item: { |
| 35 | + "@type": "Course", |
| 36 | + url: `//www.handbook.unsw.edu.au/undergraduate/courses/${new Date().getFullYear()}/${ |
| 37 | + course.courseCode |
| 38 | + }`, |
| 39 | + name: course.title, |
| 40 | + description: course.description, |
| 41 | + provider: { |
| 42 | + "@type": "CollegeOrUniversity", |
| 43 | + name: "University of New South Wales", |
| 44 | + sameAs: "https://www.unsw.edu.au/", |
| 45 | + }, |
| 46 | + aggregateRating: { |
| 47 | + "@type": "AggregateRating", |
| 48 | + ratingCount: course.reviewCount, |
| 49 | + ratingValue: course.reviewCount === 0 ? 0 : course.overallRating, |
| 50 | + bestRating: 5, |
| 51 | + }, |
| 52 | + offers: [ |
| 53 | + { |
| 54 | + "@type": "Offer", |
| 55 | + category: "Paid", |
| 56 | + }, |
| 57 | + ], |
| 58 | + hasCourseInstance: course.terms.map((term: number) => ({ |
| 59 | + "@type": "CourseInstance", |
| 60 | + courseMode: "Blended", |
| 61 | + courseSchedule: { |
| 62 | + "@type": "Schedule", |
| 63 | + repeatCount: term === 0 ? 5 : 10, |
| 64 | + repeatFrequency: "Weekly", |
| 65 | + }, |
| 66 | + })), |
| 67 | + }, |
| 68 | + })), |
| 69 | + }; |
| 70 | + |
| 71 | + return ( |
| 72 | + <div> |
| 73 | + {/* SCRIPT FOR SEO - do not touch*/} |
| 74 | + <script |
| 75 | + type="application/ld+json" |
| 76 | + dangerouslySetInnerHTML={{ __html: JSON.stringify(metaLD) }} |
| 77 | + /> |
| 78 | + {/* Landing page graphic */} |
| 79 | + <Image |
| 80 | + src={navbar} |
| 81 | + width={1000} |
| 82 | + height={500} |
| 83 | + alt="landing page graphic" |
| 84 | + layout="responsive" |
| 85 | + priority |
| 86 | + className="block" |
| 87 | + /> |
| 88 | + {/* SECTION 1 - HEADER */} |
| 89 | + <Header /> |
| 90 | + {/* SECTION 2 - "OUR FEATURES" */} |
| 91 | + <Features /> |
| 92 | + {/* SECTION 3 - "PROUDLY SPONSORED BY" */} |
| 93 | + <NewSponsorships /> |
| 94 | + {/* BOTTOM OF PAGE */} |
| 95 | + </div> |
| 96 | + ); |
| 97 | +} |
0 commit comments