Skip to content

Commit fd2aa27

Browse files
committed
Static generation for degree pages
Add automatic sitemap generation Remove language switcher until cloudflare issues have been resolved
1 parent cad671f commit fd2aa27

File tree

9 files changed

+264
-30
lines changed

9 files changed

+264
-30
lines changed

components/header/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ const Header = ({ enableHideOnScrollUp }: HeaderProps) => {
156156
</Tooltip>
157157
</HStack>
158158

159-
{/* Language switcher */}
160-
<LanguageSwitcher />
159+
{/* TODO: Language switcher */}
160+
{/* <LanguageSwitcher /> */}
161161

162162
{/* Hamburger mobile */}
163163
<IconButton

components/header/partials/sidebar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ const Sidebar = ({ isOpen, onClose, navItems }: SidebarProps) => {
106106
})}
107107
</VStack>
108108

109-
<HStack justify={"space-between"}>
109+
{/* <HStack justify={"space-between"}>
110110
<Text fontSize="sm" fontWeight="medium" color={textColor}>
111111
{t("sidebar.changeLanguage")}
112112
</Text>
113113
114114
<LanguageSwitcher isInSidebar />
115-
</HStack>
115+
</HStack> */}
116116

117117
<Box borderTop="1px solid" borderColor={useColorModeValue("gray.200", "gray.700")} pt={3} />
118118

lib/api/degrees.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ export async function getStringDegrees(): Promise<Result<string[]>> {
2020
export async function getDegreesForSearchBox(searchText: string): Promise<Result<Degree[]>> {
2121
return getAsync(`${apiEndpoint}/search-degrees?q=${searchText}`)
2222
}
23+
24+
export async function getSlugDegrees(): Promise<Result<Array<string>>> {
25+
return getAsync(`${apiEndpoint}/slug-degrees`)
26+
}

next-sitemap.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import('next-sitemap').IConfig} */
2+
module.exports = {
3+
siteUrl: "https://studentiunimi.it",
4+
generateRobotsTxt: false,
5+
sitemapSize: 7000,
6+
changefreq: "daily",
7+
priority: 0.7,
8+
generateIndexSitemap: false,
9+
transform: async (config, path) => {
10+
const cleanPath = path.replace(/^\/it/, "")
11+
return {
12+
loc: cleanPath === "" ? "/" : cleanPath,
13+
changefreq: "daily",
14+
priority: 0.8,
15+
lastmod: new Date().toISOString(),
16+
}
17+
},
18+
}

next.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import type { NextConfig } from "next"
22

33
const nextConfig: NextConfig = {
44
i18n: {
5-
locales: ["it", "en"],
5+
locales: ["it"],
66
defaultLocale: "it",
7+
localeDetection: false,
78
},
89
images: {
910
remotePatterns: [
@@ -21,6 +22,11 @@ const nextConfig: NextConfig = {
2122
destination: "/degrees/:slug",
2223
permanent: true,
2324
},
25+
{
26+
source: "/it/:path*",
27+
destination: "/:path*",
28+
permanent: true,
29+
},
2430
]
2531
},
2632
}

package-lock.json

Lines changed: 37 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"web": "next dev",
88
"proxy": "lcp --proxyUrl https://api.studentiunimi.it/api/ --port 8010",
99
"build": "next build",
10+
"postbuild": "next-sitemap",
1011
"start": "next start",
1112
"lint": "next lint",
1213
"format": "prettier --write ."
@@ -26,6 +27,7 @@
2627
"next-i18next": "^15.4.2",
2728
"next-intl": "^4.3.5",
2829
"next-seo": "^6.8.0",
30+
"next-sitemap": "^4.2.3",
2931
"react": "19.1.0",
3032
"react-dom": "19.1.0",
3133
"zustand": "^5.0.8"

pages/degrees/[slug].tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import ItemList from "@/components/item-list"
44
import PrivacyButton from "@/components/privacy/button"
55
import CourseCard from "@/components/course-card"
66
import DegreeGroupCard from "@/components/degree-group-card"
7-
import { GetServerSideProps } from "next"
8-
import { getVerboseDegreeBySlug } from "@/lib/api/degrees"
7+
import { GetServerSideProps, GetStaticPaths, GetStaticProps } from "next"
8+
import { getSlugDegrees, getVerboseDegreeBySlug } from "@/lib/api/degrees"
99
import { getCourses } from "@/lib/api/courses"
1010
import { getDegreeAdmins } from "@/lib/api/admins"
1111
import { getRepresentatives } from "@/lib/api/representatives"
@@ -159,7 +159,23 @@ const replaceUnderscore = (str: string): [string, boolean] => {
159159
return [replaced, replaced !== str]
160160
}
161161

162-
export const getServerSideProps: GetServerSideProps<DegreePageProps> = async ({ locale, params }) => {
162+
export const getStaticPaths: GetStaticPaths = async () => {
163+
const slugsResponse = await getSlugDegrees()
164+
165+
const slugs = slugsResponse.value
166+
167+
const paths =
168+
slugs?.map((slug) => ({
169+
params: { slug },
170+
})) ?? []
171+
172+
return {
173+
paths,
174+
fallback: "blocking",
175+
}
176+
}
177+
178+
export const getStaticProps: GetStaticProps<DegreePageProps> = async ({ locale, params }) => {
163179
const messages = await loadMessages(locale as "it" | "en", ["common", "seo", "degrees"])
164180

165181
const degreeSlug = params!.slug as string
@@ -168,15 +184,19 @@ export const getServerSideProps: GetServerSideProps<DegreePageProps> = async ({
168184
if (hasReplaced) {
169185
return {
170186
redirect: {
171-
destination: `/courses/${fixedSlug}`,
172-
permanent: false,
187+
destination: `/degrees/${fixedSlug}`,
188+
permanent: true,
173189
},
174190
}
175191
}
176192

177193
const degreeResult = await getVerboseDegreeBySlug(degreeSlug)
178194
const degree = degreeResult.value
179195

196+
if (!degree) {
197+
return { notFound: true }
198+
}
199+
180200
const teachingCoursesResult = degree ? await getCourses(String(degree.pk)) : { value: [] }
181201

182202
const adminsResult = await getDegreeAdmins(degreeSlug)
@@ -203,7 +223,7 @@ export const getServerSideProps: GetServerSideProps<DegreePageProps> = async ({
203223
representatives: representativesResult.value ?? [],
204224
mainGroup,
205225
},
206-
notFound: degree === undefined,
226+
revalidate: 60 * 60 * 24,
207227
}
208228
}
209229

0 commit comments

Comments
 (0)