It seems that next-sitemap is unable to produce sitemaps for dynamic paths, so we're switching back to dynamic server-side sitemap generation
This commit is contained in:
@@ -5,7 +5,7 @@ import { getSchedule } from '@/app/agregator/schedule'
|
||||
import { NextSerialized, nextDeserializer, nextSerialized } from '@/app/utils/date-serializer'
|
||||
import { NavBar } from '@/widgets/navbar'
|
||||
import { LastUpdateAt } from '@/entities/last-update-at'
|
||||
import { groups } from '@/shared/data/groups'
|
||||
import groups from '@/shared/data/groups.json'
|
||||
import crypto from 'crypto'
|
||||
import React from 'react'
|
||||
import { getDayOfWeek } from '@/shared/utils'
|
||||
@@ -61,6 +61,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr
|
||||
if (group && Object.hasOwn(groups, group) && group in groups) {
|
||||
let schedule
|
||||
let parsedAt
|
||||
const groupName = group as keyof typeof groups
|
||||
|
||||
const cachedSchedule = cachedSchedules.get(group)
|
||||
if (cachedSchedule?.lastFetched && Date.now() - cachedSchedule.lastFetched.getTime() < maxCacheDurationInMS) {
|
||||
@@ -68,9 +69,10 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr
|
||||
parsedAt = cachedSchedule.lastFetched
|
||||
} else {
|
||||
try {
|
||||
schedule = await getSchedule(...groups[group])
|
||||
const group = groups[groupName] as [number, string]
|
||||
schedule = await getSchedule(...group)
|
||||
parsedAt = new Date()
|
||||
cachedSchedules.set(group, { lastFetched: new Date(), results: schedule })
|
||||
cachedSchedules.set(groupName, { lastFetched: new Date(), results: schedule })
|
||||
} catch(e) {
|
||||
if (cachedSchedule?.lastFetched) {
|
||||
schedule = cachedSchedule.results
|
||||
@@ -103,7 +105,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr
|
||||
props: nextSerialized({
|
||||
schedule: schedule,
|
||||
parsedAt: parsedAt,
|
||||
group: groups[group][1]
|
||||
group: groups[groupName][1]
|
||||
})
|
||||
}
|
||||
} else {
|
||||
|
||||
4
src/shared/data/groups.json
Normal file
4
src/shared/data/groups.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"ps7": [146, "ПС-7"],
|
||||
"pks35k": [78, "ПКС-35к"]
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export const groups: { [group: string]: [number, string] } = {
|
||||
ps7: [146, 'ПС-7'],
|
||||
pks35k: [78, 'ПКС-35к']
|
||||
}
|
||||
Reference in New Issue
Block a user