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

4
.gitignore vendored
View File

@@ -34,4 +34,6 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts
.env
.env
public/sitemap.xml

1
.npmrc Normal file
View File

@@ -0,0 +1 @@
enable-pre-post-scripts=true

12
next-sitemap.config.js Normal file
View File

@@ -0,0 +1,12 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const groups = require('./src/shared/data/groups.json')
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: 'https://kspsuti.ru',
generateRobotsTxt: false,
generateIndexSitemap: false,
changefreq: 'weekly',
exclude: ['/'],
additionalPaths: async () => Object.keys(groups).map(groupName => `/${groupName}`)
}

View File

@@ -5,6 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"postbuild": "next-sitemap",
"start": "next start",
"lint": "next lint"
},
@@ -24,6 +25,7 @@
"jsdom": "^22.1.0",
"lucide-react": "^0.279.0",
"next": "latest",
"next-sitemap": "^4.2.3",
"next-themes": "^0.2.1",
"node-html-parser": "^6.1.10",
"node-telegram-bot-api": "^0.63.0",

21
pnpm-lock.yaml generated
View File

@@ -50,6 +50,9 @@ dependencies:
next:
specifier: latest
version: 13.5.3(react-dom@18.2.0)(react@18.2.0)
next-sitemap:
specifier: ^4.2.3
version: 4.2.3(next@13.5.3)
next-themes:
specifier: ^0.2.1
version: 0.2.1(next@13.5.3)(react-dom@18.2.0)(react@18.2.0)
@@ -136,6 +139,10 @@ packages:
dependencies:
regenerator-runtime: 0.14.0
/@corex/deepmerge@4.0.43:
resolution: {integrity: sha512-N8uEMrMPL0cu/bdboEWpQYb/0i2K5Qn8eCsxzOmxSggJbbQte7ljMRoXm917AbntqTGOzdTu+vP3KOOzoC70HQ==}
dev: false
/@eslint-community/eslint-utils@4.4.0(eslint@8.50.0):
resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -3063,6 +3070,20 @@ packages:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
dev: true
/next-sitemap@4.2.3(next@13.5.3):
resolution: {integrity: sha512-vjdCxeDuWDzldhCnyFCQipw5bfpl4HmZA7uoo3GAaYGjGgfL4Cxb1CiztPuWGmS+auYs7/8OekRS8C2cjdAsjQ==}
engines: {node: '>=14.18'}
hasBin: true
peerDependencies:
next: '*'
dependencies:
'@corex/deepmerge': 4.0.43
'@next/env': 13.5.3
fast-glob: 3.3.1
minimist: 1.2.8
next: 13.5.3(react-dom@18.2.0)(react@18.2.0)
dev: false
/next-themes@0.2.1(next@13.5.3)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==}
peerDependencies:

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к']
}

View File

@@ -33,7 +33,7 @@
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
, "next-sitemap.config.js" ],
"exclude": [
"node_modules"
]