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:
VityaSchel
2023-10-12 18:35:39 +04:00
parent 3af808d77c
commit 813fa218e9
9 changed files with 50 additions and 10 deletions

View File

@@ -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 {

View File

@@ -0,0 +1,4 @@
{
"ps7": [146, "ПС-7"],
"pks35k": [78, "ПКС-35к"]
}

View File

@@ -1,4 +0,0 @@
export const groups: { [group: string]: [number, string] } = {
ps7: [146, 'ПС-7'],
pks35k: [78, 'ПКС-35к']
}